I'm trying to create an AlertDialog with an ArrayAdapter to show a list of items for the user to select form (single choice). However, I would like to show which item was previously selected. Since selecting an item automatically closes the dialog, my thought was to set a custom background color for the previously selected item. Below is a mockup of what I'm hoping to achieve:
The code I have currently is this:
private void showCustomAlert(int alertNumber, int parentTaskId) {
Log.w(LOGTAG, showCustomAlert);
int alertNumberID = Integer.parseInt(task1_id);
if (alertNumber==2) alertNumberID = Integer.parseInt(task2_id);
else if (alertNumber==3) alertNumberID = Integer.parseInt(task3_id);
else if (alertNumber==4) alertNumberID = Integer.parseInt(task4_id);
AlertDialog.Builder builderSingle = new AlertDialog.Builder(thisActivity);
builderSingle.setIcon(R.drawable.icon);
builderSingle.setTitle("Select Task:");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(thisActivity,
android.R.layout.select_dialog_singlechoice);
for (int i=0; i<taskList.size(); i++) {
BT_item tmpItem = taskList.get(i);
if (BT_strings.getJsonPropertyValue(tmpItem.getJsonObject(),"task_parent","").equalsIgnoreCase(parentTaskId + ""))
arrayAdapter.add(BT_strings.getJsonPropertyValue(tmpItem.getJsonObject(),"task_name",""));
}
builderSingle.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int taskSelected) {
Log.w(LOGTAG, "task selected");
}
});
builderSingle.show();
}