0

Here is what I do in onCreateView (in fragment):

NewsAdapter adapter = new NewsAdapter(getActivity(), newsList, R.layout.news_list_item);
newsListView.setAdapter(adapter);
newsListView.setOnItemClickListener(this);

And here is onItemClick:

@Override                                                                         
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    view.setBackgroundResource(R.drawable.list_item_back_selected);
}

And the problem is when I tap on the first item then the last visible is only highlighted. On the 2nd - 1st and 2nd from the end. 3rd - 2nd, last and 3rd from the end etc.
I checked that view is a really the item was clicked by looking inside mChild array. Currently I can't figure out the reason. Do you have any ideas? Let me know if more datailed code is required. Thanks in advance.
The application was tested on 10 inches tablet emulator, Android 2.3.3

Sergey Metlov
  • 25,747
  • 28
  • 93
  • 153

3 Answers3

2

Removing android:choiceMode="singleChoice" attribute of the listview fixed the problem.

Sergey Metlov
  • 25,747
  • 28
  • 93
  • 153
0

Not sure if thats it but it seems like the same issue that I have encountered some time ago :

getting View for ListView item / reverse order on 2.2; works on 4.0.3

try wraping it in Runnable

something like :

view.post(new Runnable(
   run(){
      view.setBackground...
   }
)) 
Community
  • 1
  • 1
AndroidGecko
  • 14,034
  • 3
  • 35
  • 49
0

I think you have to call adapter.notifyDataSetChanged() when you affect the new background to tell the adapter that you want to refresh the view.

Esteam
  • 1,911
  • 1
  • 16
  • 24