1

My activity includes 2 fragments. Fragment 1 in the left contains a ListView, let's call listView1, and fragment 2 in the right contains a GridView. I implemented a onItemSelectedListener to send data to a remote server each time an item in listView1 is selected (users use D-pad to navigate). The listener is as below:

listView1.setOnItemSelectedListener(new OnItemSelectedListener(){
    public void onItemSelected(AdapterView<?> parent, View view, 
                                          int position, long id){
        //send data to sever here
        sendData();
    }
});

It's ok when I navigate around in the ListView. The sendData() method insides onItemSelected() was called as normal. But the problem is each time I navigate to my GridView and then navigate back to the previous selected item in listView1, the onItemSelected and sendData() method haven't fired off any more. I did a search and found in android reference that the onItemSelected method is invoked only when the newly selected position is different from the previously selected position.

So how can i make onItemSelected fire off even when I navigate back to previous selected item?

Thanks in advances!

vqtr
  • 115
  • 1
  • 8

1 Answers1

0

Use onListItemClick instead:

@Override
public void onListItemClick(ListView parent, View view, int position, long id) {
    sendData();
}
Marcin S.
  • 11,161
  • 6
  • 50
  • 63
  • Thanks Marcin S. But it requires users to perform "press enter" action which may reduces their experience since they use D-Pad to navigate. – vqtr Jan 25 '13 at 02:39