This question has been asked a lot of times and I've systematically gone through each and tried to find which version of performItemClick
works. Unfortunately I just can't get any of them to work despite my onclick method being called.
I have a listview with 5 items embedded into a fragment. This fragment is controlled by a fragmentstatepageradapter and a viewpager. I'm trying to restore the saved state.
lv.setAdapter(new SimpleAdapter(getActivity(), list,
R.layout.list_imageview, new String[] { "answer" },
new int[] { android.R.id.text1 }));
The simple adapter takes in a custom layout which has a textview and imageview within a layout. Initially the imageview is null and on click it is set to a tick or cross. This works when clicking the items myself just doesn't work programatically as follows:
@Override
public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
for (int i = 0; i < 5; i++) {
lv.performItemClick(lv.getAdapter().getView(i, null, null),
i, i);
Log.e("restoring state", "" + i);
}
}
}
I can confirm that onViewStateRestored
is called and onItemClick
is also called. I assume it's a problem in the way I'm performing the item click. I am currently just trying to get it work; I know I haven't yet checked which items have been clicked to selectively click them but that's an easy boolean[]
away.
I thank you for your help, and sorry for such a simple question that's been repeated quite a few times; despite reading them I am still unable to get them to work.