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

asked Jun 11, 2013 at 19:26

3 Answers 3

2

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

answered Jun 11, 2013 at 19:40
Sign up to request clarification or add additional context in comments.

Comments

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...
 }
)) 
answered Jun 11, 2013 at 19:35

1 Comment

Unfortunally didn't help. But thanks for the link it reminded me about the android:choiceMode that I tried before.
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.

answered Jun 11, 2013 at 19:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.