Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Recall selections when using .setMultiChoiceItems with AlertDialog  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented multiple checkboxes in an AlertDialog. However, I am now looking for a simple way to recall the selected checkboxes if the AlertDialog is reopened.

The issue arises here...



A new instance of the AlertDialog is called every time. So, I was supposing that if there was a way to preserve the previous state, that should do the trick. Does anyone have experience doing this? Or suggestions?

Thanks y'all!
 
Adam Wentz
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, after doing extensive digging, I came across this tutorial:

Show/Create AlertDialog with multiple choices in android

It resolves the issue of recalling previous selections in the checkbox AlertDialog by utilizing a boolean array. It needed only minor tweaking to make it work perfectly for my purpose.

In the event that the aforementioned page should become unavailable in the future, here is the code from the referenced tutorial:

MainActivity.java



activity_main.xml
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!