Hello,
I've created a custom ListView by extending SimpleCursorAdapter. The result is IMAGE + CheckedTextView (Text + Checkbox).
After I had issues with the wrong checkboxes getting checked (see here) I had to remove lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); from onCreate.
Now I click on a ListItem line and it checks the right checkbox.
What I'm trying to do is make a LinearLayout.VISIBLE when 1 or more checkboxes are checked AND make LinearLayout.GONE when no checkbox is checked.
Here is the code:
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckedTextView markedItem = (CheckedTextView) view.findViewById(R.id.btitle);
if (!markedItem.isChecked()) {
markedItem.setChecked(true);
//show bottom control panel
findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.VISIBLE);
} else {
markedItem.setChecked(false);
SparseBooleanArray lala = ((ListView) parent).getCheckedItemPositions();
//if no checkbox is checked, hide bottom control panel
if (lala == null) {
findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.INVISIBLE);
}
}
view.refreshDrawableState();
//showSortBtn(markedItem);
} });
This is how I bind the listView to the custom adapter:
projection = new String[] { Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.FAVICON, Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL };
displayFields = new String[] { Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.FAVICON, Browser.BookmarkColumns.URL };
int[] displayViews = new int[] { android.R.id.icon, android.R.id.text1 };
cur = managedQuery(BOOKMARKS_URI, projection,
Browser.BookmarkColumns.BOOKMARK + " == 1", null, Browser.BookmarkColumns.VISITS + " DESC");
setListAdapter(new ImageCursorAdapter(this,
android.R.layout.simple_list_item_single_choice, cur,
displayFields, displayViews));
I have two issues with this:
if I check 2 or more checkboxes and then uncheck only one, the LinearLayout disappears which means
SparseBooleanArray lala = ((ListView) parent).getCheckedItemPositions();
is null. why is it null if there are still other checkboxes checked?if I switch
findViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.INVISIBLE);
tofindViewById(R.id.bottom_control_bar).setVisibility(LinearLayout.GONE);
(like I want to do) the first checkbox is being checked correctly and after the LinearLayout is GONE, everything is a mess again, just like on my previous question.
Appreciate any help!