I have been looking at Android AlertDialog, and its easy enough to use the setItems(...) to add a list of Strings that are to be shown.
However, in most cases you want a list showing nice Strings, but when selecting something from the list you want the actual value and not the String.
I have been unable to find how to do that in an easy and nice way.
Tips? =)
final Button Button1 = (Button) findViewById(R.id.Button1);
Button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
final CharSequence[] items = { "String 1", "String 2", "String 3" };
// INstead of a string array, I want something like:
// ArrayList<CustomObject> test = new ArrayList<CustomObject>(myArray);
// And the CustomObject has a toString() and also a value. This array should in the best of worlds be the base for the list below =)
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(LanguageHandler.GetString("Test"));
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// *** I want to get the value here! ***
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
Instead of
CharSequence[] items = { "String 1", "String 2", "String 3" };
you can use aCustom Adapter
in your Alert Dialog,Something like,
Your list_row.xml file
And your ListAdapter something like,