=============== Problem description ====================
Effect description:
A list like the built-in mail application in Android
1. Each item is a checkbox on the left and content on the right.
2. If you click the checkbox area on the left, the checkbox of the item will be selected and the content will not be opened.
3. If you click the text content area on the right, a new activity is opened to show the body of the email.
4. After multiple selections, You Can batch Delete the list items at a time.
I thought about this effect and didn't think of a good idea.
I defined an item. XML, set the checkbox and textview, and inherited the baseadapter to create the corresponding adapter.
There are the following problems:
1. Set the focusable of the checkbox to false. Otherwise, the listview will not be able to monitor the onitemclick event.
2. You can listen to the listview onitemclick event, and click to open the new content activity.
3. the problem is, how can I monitor the selected/unselected events of the checkbox and record the position of the checkbox in the list after listening to this selected event, save it to an index list and record the selected status of each item.
4. If you select the checkbox item in the onitemclick event of listview, you can modify the status. However, when you click the content area on the right, a new activity is opened. How to control whether to set the checkbox response or open a new activity based on the clicked area?
============= Solution 1 ======================
In fact, the root cause of your problem is: because the existence of checkbox affects the listview response to click events, you can consider adding android to the listview layout file: descendantfocusability = "" to avoid the impact of sub-controls.
============= Solution 2 ======================
Reference the reply from itbailei on the 6th floor:
Quote: reference the reply from txfast on the fifth floor:
Quote: reference the reply from itbailei on the 4th floor:
(1) This involves the principle of the event distribution mechanism, because the onthoch event of the checkbox will block the Click Event of the parent layout, so you can block the corresponding event, You can Google it, there are many solutions.
(2) If you say yes, it's not a problem.
(3) checkbox is an item in listview. It is not a problem to obtain the data in the corresponding item list.
(4) The first problem is solved. This is certainly not a problem.
In summary, you only asked a question.
1. The onclick event of the checkbox shields the events of the container control. You can solve this problem by setting the focusable = false of the checkbox.
2. Actually, how can I monitor the checked event of the checkbox and obtain the postion position parameter of the listview when I check the checkbox?
In actual operations, the checkbox check will not trigger the onitemclick event of the listview.
The same, as long as you properly handle the mutual impact of these two events, there will be no mutual blocking, you can refer to the blog http://cache.baiducontent.com/C? M = Response & P = Response & newp = Response & User = Baidu & fm = SC & query = chekbox + % Ba % cdlistview % B9 % B2 % B4 % E6 & qid = 971ce8bb0003e68f & amp; P1 = 2
The correct reference address is http://blog.csdn.net/gyflyx/article/details/6567701
============= Solution 3 ======================
After reading the answers from the upstairs, there are a variety of things...
In fact, it is so complicated where you find your checkbox in getview, and then set the oncheckchangelistener listener for him, and write an interface in the adapter, then, call back the status in the checkbox listener, implement your custom interface in the activity, and get the status returned by the callback listener (Observer mode ). Your own listview has its own onitemclicklistener. You can set this built-in item listener for listview to achieve the desired effect.
Also, the record status you mentioned has nothing to do with this. You add an attribute (in fact, adding a member variable) to the data (bean) corresponding to each position, for example, ischeck). When the checkbox listener in getview is triggered, set the ischeck attribute corresponding to the data to the current status of the checkbox. The status of the find checkbox in your getview is set based on the ischeck status of the corresponding data. Then, when you delete one or more selected items, it is equivalent to listening to the deletion event in the activity and checking the data in the data, delete the data from the dataset. just remove it in a minute.
What is the effect of listview with checkbox like the built-in mail application?