Android でシンプルなレストラン アプリケーションを開発しています。メニューと各メニュー項目に対応する膨張したサブメニュー項目を使用しました。ユーザーが警告ダイアログで [はい] を選択した場合にのみ、リストに料理の名前を追加する方法を知りたいと思っていました。およびその逆。これが私のコードです
public boolean onOptionsItemSelected(MenuItem m)
{
super.onOptionsItemSelected(m);
switch(m.getItemId())
{
case R.id.Chicken_Biryani:
selectedItem.add(m.getTitle().toString());
cost.add(150);
Toast.makeText(getApplicationContext(),"Hyderabadi special: Chicken biryani costs 150 Rs"+selectedItem, Toast.LENGTH_LONG).show();
showDialog(ALERT_DIALOG);
break;
case R.id.Butter_Chicken:
selectedItem.add(m.getTitle().toString());
cost.add(150);
Toast.makeText(getApplicationContext(),"Now with Punjabi Tadka: Butter Chicken costs 150 Rs", Toast.LENGTH_LONG).show();
showDialog(ALERT_DIALOG);
break;
........
public Dialog onCreateDialog(int id) {
switch(id)
{
case ALERT_DIALOG:
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("Buy Items");
ab.setMessage(" You have added the item to your cart ");
ab.setIcon(R.drawable.shopcart);
ab.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
Toast.makeText(getApplicationContext(),"Item added to cart your cart contains "+selectedItem.size()+" Items", Toast.LENGTH_LONG).show();
}});
Dialog ad = ab.create();
return ad;
}
return null;
}
// ユーザーが alertdiaolog で yes を選択した場合にのみ、onOptionsItemSelected のデータをリストに渡す方法