How to use setMultiChoiceItems () with a Custom AlertDialog that uses an efficient massive adapter?

I am writing a music player that uses a special adapter that extends BaseAdapter (performance adapter), which I want to display in AlertDialog using setAdapter() , where the user can either click on one of the songs to switch to this position in the playlist OR check the songs for delete from playlist. I tried using a custom click listener so that the user can simply click for a long time to remove an item from the list, but listview just doesn't work correctly ... it deleted the wrong items (those that were at the end) even though the ArrayList contains the correct playlist items. .. (when I deleted the item from the ArrayList , I passed it to an adapter called notifyDataSetChanged ... but it just doesnโ€™t work, as I mentioned. There is a definite error in the AlertDialog ListView ... because there is no reason for it to deleted the result you're from the end, not from the right element.

So ... the next method I would like to try is to use the setMultiChoiceItems() method for AlertDialog ... but it doesn't seem to work with the custom adapter ... only simple arrays, Should I subclass the AlertDialog and Override setMultiChoiceItems() method setMultiChoiceItems() or is there a way I can get it to work with the ArrayAdapter ?

Basically, I cannot figure out how to iterate over the list generated by AlertDialog , or even somehow convey this view. Also, I don't think I can even listen to clicks on checkboxes if I add them to a string. Any help would be greatly appreciated.

EDIT: Asking questions here is like magic ... I answered my question ... that's how I did it. I added a tooltip to each checkbox , which is the item position in the ArrayList . Then I used OnCheckedChangeListener to capture the selection. When you set the tooltip, it adds the text to the checkbox ... since the background of the AlertDialog white (even for elements with pressed?) I just set the tooltip text color to transparent.

 holder.check.setHintTextColor(Color.TRANSPARENT); holder.check.setHint(String.valueOf(position)); holder.check.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int position = Integer.parseInt((String) buttonView.getHint()); Log.v("onCheckedChanged", "Checked: "+isChecked+" returned: "+position+" which should be "+getItem(position).name); } }); 
+7
android alertdialog
source share
1 answer

Address This and This

Then pass the link to byte [] in setMultiChoiceItems().

 final boolean[] booleans = {false, true, false, true, false, false, false}; 

Then check the booleans value inside setPositiveButton().

If you need to pass this AlertDialog , then AlertDialog and create a boolean field as described in 1.

+3
source share

All Articles