I implemented a View stack system for my Android application, which, upon pushing a new View removes the current view in the target layout, stores it in the stack and then adds the new View to the layout.
It works flawlessly until I try storing and then restoring a View containing a ListView. When doing so, the ListView receives no itemClick events, although it does scroll.
The code for the stack system is as follows:
Stack<View> viewStack;
public View pushView(View v) {
// 1. Get reference to main content panel
LinearLayout content = (LinearLayout) findViewById(R.id.contentPanel);
View last = content.getChildAt(0);
// Pushing old to stack
viewStack.push(last);
// 2. Clear it
content.removeAllViews();
// 3. Add new View
content.addView(v);
return last;
}
public View popView() {
if (!viewStack.isEmpty()) {
// 1. Get reference to main content panel
LinearLayout content = (LinearLayout) findViewById(R.id.contentPanel);
View last = content.getChildAt(0);
// 2. Clear it
content.removeAllViews();
// 3. Add last View
content.addView(viewStack.pop());
// Pushing old to stack
return last;
} else {
return null;
}
}
Curiously, the other items in the View that contains the ListView (CheckBoxes and a Button) DO receive clickEvents. I suspect: 1. The ListView has lost focus so it won't receive those events, or 2. The ListView has been detached of the onItemClickListener
Thanks in advance!
If you have set "clickable" as "true" in you layout in xml file then remove it from every where. then you can try...
If you are declaring anywhere then only. If you are declaring "view_name.setClickable(true)" then remove this line. One more thing if you are using ontouchlistener then always return false. Actually i have faced similar problem in which I was using listview and imageview in listview row. My imageview was receiving click event but listview was not receiving onitemclick event because i had set imageview as clickable in my layout.