Reputation: 4968
in my app when i touch an edit box i am opening an dialog box which consists of a 3 Character sequence as Full format, year format and cancel. When i select the one among them another dialog box gets opened.
When the second dialog box gets opened i want the first dialog box to be either dismissed or cancelled automatically, but it is not happening..... Following is the part of my code
private OnTouchListener bdListener = new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
DOBalert();
return isexists;
}
private void DOBalert()
{
Builder DOBbuilder = new AlertDialog.Builder(RestingSpotAdd.this);
DOBbuilder.setTitle("Date of Birth");
final CharSequence[] items = {"YearFormat", "FullFormat","Cancel"};
DOBbuilder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
int i = item;
if(i==0)
{
dialog.dismiss();
yearFormat();
}
else if(i==1)
{
dialog.cancel();
fullFormat();
}
else if(i==2)
{
cancel();
}
}
public void yearFormat()
{
showDialog(YEARSELECTOR_ID);
}
public void fullFormat()
{
showDialog(DATEYEARMONTHSELECTOR_ID);
}
});
AlertDialog DOBalert = DOBbuilder.create();
DOBalert.show();
}
};
Please help me friends......
Upvotes: 1
Views: 748
Reputation: 4673
Why are you using onTouchListener
instead of onClickListener
?
The problem is that when you click an item in your list dialog, the touch event of the dialog is also fired causing it to be shown again.
Upvotes: 3