Summary of Android ListView problems

Summary of Listview problems:

1. Check view selection in item is
caused by confusing ListView caching mechanism.
The solution can be:
first call the holder.cbIamge.setOnCheckedChangeListener method in the getView method in the adapter, and
then call the holder.cbIamge.setChecked method to solve the problem. (holder.cbIamge) is a CheckBox object.
If you want to record the number of CheckBox selected in real time, the above solution still doesn't work. After searching on the Internet, I finally found a solution. Record it here. The URL is: http://stackoverflow.com/questions /6100518/checkbox-auto-call-oncheckedchange-when-listview-scroll
The solution is:
when calling holder.cbIamge.setChecked() in the adapter, first set the CheckBox listener to null (holder.cbIamge.setOnCheckedChangeListener(null) ;)
Then call the holder.cbIamge.setChecked() method
and finally reset the listener of the CheckBox holder.cbIamge.setOnCheckedChangeListener(new OnCheckedChangeListenerImpl(holder, position));

2. The content of the item is
   caused by the reuse of the repeated View, each time the getview is called set its content

3. The object record error of the first item
   once encountered such a requirement in the project, select an item in the GridView, mark the selected item, my solution is: use a sharepreference or the id of the database or other records that are selected, When it is judged that the id of the item is the same as the id of the record when gettingView, mark the item (can be set the background color, etc.), record the marked ViewHolder lastHolder, and restore the previous lastHolder when the next item is selected.
In such a case, there will be problems. Select the first item, exit the application, reopen the application, and select the second item. At this time, the first item is still selected.
Another case with the same principle: Select item1, a certain EditText on the editing interface will pop up the keyboard, hide the keyboard, and select the second case. At this time, the first item is still selected.
Let’s talk about the second reason first:
Activity can configure the properties of windowSoftInputMode. If it is not configured when the keyboard pops up, the interface will be redrawn. When the height of ListView is set to wrapcontent or matchparent, the first data of listView will be drawn multiple times, so record The lastHolder does not necessarily match the first item we see, this is the operation of the lastHolder without any change. In this way, the previous case can also be explained. The first item is drawn multiple times, and
the object recorded by lastHolder is not the object seen on the interface.

solution:
For the first item drawn multiple times due to the keyboard pop-up, you can set windowSoftInputMode to adjustNothing so that the interface will not be redrawn when the keyboard pops up, but it cannot solve the first scene. You can rewrite the GridView or Listview to record the flag in the onMeasure method. If the drawing is displayed, the lastHolder is not reassigned.

The last attachment is to attach an Android development UI development suggestion document

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043000&siteId=291194637