=============== Problem description ====================
I am a newbie and have encountered the following problems during the learning process:
The number of items in listview exceeds the display area. For example, if there are 20 items in total, 10 items can be displayed in the display area. After clicking the Select All button, click Delete to delete only the 10 display areas. When the Select All button is clicked, slide the screen and you will find that all 20 checkboxes are checked. Then click Delete again, then all 20 can be deleted normally.
How can this problem be solved? What is the problem? Viewholder? It's a bit confusing now.
============= Solution 1 ======================
Listview loads list1 and list1 contains 18 pieces of data.
Select all vertices-Click Delete to clear lis1t in the code
Select all points-delete one of the first 10 items. Save the item in the code to list2 and clear list1, listview loads list2 (of course, this is only a solution, there are a variety of other methods)
Is that all right?
============= Solution 2 ======================
Public View getview (INT position, view convertview, viewgroup parent ){
The position here is only the index of the displayed record, so no index of the undisplayed record is put in your deletemap.
If (holder. checkbox. ischecked () = true ){
Deletemap. Put (Position, (string) Holder. Id. gettext ());
} Else {
Deletemap. Remove (position); // clear the previously selected and canceled items from hashmap.
}
============= Solution 3 ======================
Reference the reply from theunforgiven on the 18 th floor:
Quote: reference the reply of gqjjqg on the 14th floor:
This idea is actually quite simple. listview is only responsible for displaying, and the actual data is saved in the adapter.
1. Click Select All. Mark all data in the adapter as selected. Refresh the listview and select all currently displayed views.
2. Slide or drag to refresh the corresponding view by clicking a single button and marking the selected or unselected data in the adapter.
3. Click Delete to delete the data in the adapter and refresh the listview.
The key is one sentence: do not rely on the subview of the listview control to check whether there is a flag.
The key to your problem is that you did something you shouldn't do during getview.
Getview only sets the display of the UI, instead of processing data. Otherwise, the UI display efficiency is affected.
// This part should be processed when you click Delete.
If (holder. checkbox. ischecked () = true ){
Deletemap. Put (Position, (string) Holder. Id. gettext ());
} Else {
Deletemap. Remove (position); // clear the previously selected and canceled items from hashmap.
}
I am very profitable in your answer. For your convenience, let me ask again.
I have some knowledge about MVC. Do you mean something similar to it? Use [application] → [logic] → [display] to implement the program. But I started to get a little confused. The above section if (holder. checkbox. ischecked () should be regarded as a "logical" part, but how can we separate it from "display" (my code is from others' code for reference and analysis, so I really don't understand without examples )? Can you give me some simple examples? In addition, should the following code be regarded as "logic" or "display?
If (checkvisible)
Holder. checkbox. setvisibility (view. Visible );
Else
Holder. checkbox. setvisibility (view. Gone );
The above if (holder. checkbox. ischecked () should be regarded as a "logical" part, but how can we separate it from "display "?
A: There is no need to check the status of the checkbox. the checkbox is also a view, but it is only used for display. Do not check its check status. We recommend that you save the check status in the adapter, instead of relying on whether the control is checked.
Can you give me some simple examples?
A: There are many examples of androidsdk's built-in sample. If you have the ability, you can read the android source code.
In addition, should the following code be regarded as "logic" or "display?
If (checkvisible)
Holder. checkbox. setvisibility (view. Visible );
Else
Holder. checkbox. setvisibility (view. Gone );
A: This part is suitable for getview processing, but the checkvisible must be changed to check the actual save status.
My personal suggestion is nothing more than learning and making progress together. If you do not understand it, we recommend that you first look at the listview workflow.
Items not in the display area cannot be deleted after listview is selected.