Chanaka Fernando
Chanaka Fernando

Reputation: 2335

Creating AleartDialog's setSingleChoiceItems() method from custome ArrayList

I have an ArrayList of custom model called Grade. This model contain getName() method that returns the name of the grade.

My requirements are to

Use this ArrayList's Grade medel's getName() method to create Alert Diolog's setSingleChoiceItems() by passing gradeNames array.

And also I want to get the selected item(Whole Grade model) back when I select on some item on the list that displayed on AlertDialog.

builder.setSingleChoiceItems(gradeNames, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

          //**Here I want to get selected item back as "Grade" Object

          notifyDataSetChanged();
        }
    });

Please help me to salve this.

Thank you!

Upvotes: 0

Views: 552

Answers (1)

will
will

Reputation: 409

Use:

  yourArrayList.get(which);

inside of setSingleChoiceItems().

Upvotes: 1

Related Questions