Recently busy, I do not know what is busy, I intend to write half of the blog, have not finished writing, today first pull a pull on the project encountered a problem, on the one hand to prevent later encounter this problem forget how to solve, on the other hand hope can provide to meet the same problem friend a train of thought.
To get started, use a checkbox in the ListView item, and when you use the normal ListView usage, you will encounter the following problem:
1.checkbox can be clicked, but the ListView item cannot be clicked
2. Unable to get what line the checkbox was clicked on
The first issue relates to the distribution of events, the next one (I will follow my understanding, easy to understand to describe), the second question my understanding is getview cannot redraw the reason, here can not get the value of position, in order to solve my problem, I need to change a way of thinking, that is, I introduced the method today : A selection event that masks the checkbox, which means that the checkbox cannot respond to the selected event, creating an illusion when the user clicks on the ListView item, using the code to control the checkbox
Well, that's about it, because the code is written directly into the project, do not write the demo, directly paste the main code, for reference only, if you have a better way to communicate with each other
1. Block Click events for checkbox
Android:clickable= "false" android:focusable= "false"
2. Define a value to control the checkbox selection
private static hashmap<integer,boolean> isSelected;
public static hashmap<integer,boolean> getisselected () { return isSelected; } public static void setisselected (Hashmap<integer,boolean> isSelected) { mydocshowadapter.isselected = isSelected; }
3. Assigning a checkbox to a value
MHolder.mCheckBox.setChecked (getisselected (). get (position));
4, assign a checkbox to the check case
Mlistview.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> Parent, View view,int position, long ID) {Viewholder holder = (viewholder) view.gettag (); Holder.mCheckBox.toggle (); Mydocshowadapter.getisselected (). Put (position, holder.mCheckBox.isChecked ());}});
Today is here, there are questions can leave a message ...
1. Block Click events for checkbox
Android:clickable= "false" android:focusable= "false"
2. Define a value to control the checkbox selection
private static hashmap<integer,boolean> isSelected;
public static hashmap<integer,boolean> getisselected () { return isSelected; } public static void setisselected (Hashmap<integer,boolean> isSelected) { mydocshowadapter.isselected = isSelected; }
3. Assigning a checkbox to a value
MHolder.mCheckBox.setChecked (getisselected (). get (position));
4, assign a checkbox to the check case
Mlistview.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> Parent, View view,int position, long ID) {Viewholder holder = (viewholder) view.gettag (); Holder.mCheckBox.toggle (); Mydocshowadapter.getisselected (). Put (position, holder.mCheckBox.isChecked ());}});
Today is here, there are questions can leave a message ...
Android ListView Problem Solution with checkbox