I have a an array of values displayed in the form of dialog in android, tap on any of the item, displays that particular toast. Now if I tap on other item on this list (array) in the very next moment, that particular toast displays after short duration(Approximately 5sec) till then old toast is displayed. If I wanted to display new Toast immediately after I select/tap other item on the list what can I do ?
So can someone tell me what is the logic to achieve this ?
For instance consider this code -
String NumberOfItems[] = { "1", "2", "3" };
Activity mActivity;
int id =0;
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(R.string.dialog_heading);
builder.setSingleChoiceItems(NumberOfItems, id, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
switch(id)
{
case 0:
Toast.makeText(mActivity.getBaseContext(),"Item selected is 1",Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(mActivity.getBaseContext(),"Item selected is 2",Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(mActivity.getBaseContext(),"Item selected is 3",Toast.LENGTH_SHORT).show();
break;
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
Now Dialog containing 3 items displays, tap on 1st item displays "Item selected is 1" soon I tap on next item but it displays "Item selected is 2" after ~5sec. But if I wanted to display immediately on tap of 2nd item what can I do ?
In short what is the logic to refresh Toast ?
Any help is greatly appreciated.