2011-02-25 44 views
0
ListView menuList = (ListView) findViewById(R.id.ListView_Menu); 
String[] items = {getResources().getString(R.string.menu_item_NxtInc)}; 
ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item,items); 
menuList.setAdapter(adapt); 
menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) { 
       TextView textView = (TextView) itemClicked; 
       String strText = textView.getText().toString(); 
       if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_NxtInc))) { 
        startActivity(new Intent(EndActivity.this, NxtIncActivity.class)); 
        EndActivity.this.finish(); 
       } 

我已經使用上面的代碼在我的應用程序中創建了一個菜單。如果用戶點擊字符串menu_item_NxtInc,它們將被帶到下一個活動。我想要發生的是提示出現,說你確定要這樣做嗎?任何人都知道如何實現這一點。感謝如何創建一個提示對話框

回答

5

像這樣簡單

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Are you sure you want to do this baby?") 
     .setCancelable(false) 
     .setPositiveButton("Yuss, lets do this", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       // fire an intent go to your next activity 
      } 
     }) 
     .setNegativeButton("Err, no", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.cancel(); 
      } 
     }); 
AlertDialog alert = builder.create(); 
alert.show(); 
+1

你忘了提及節目() – ingsaurabh 2011-02-25 10:25:46

+0

哎呦,糾正。謝謝 – Reno 2011-02-25 10:28:03

+0

非常感謝! – Beginner 2011-02-25 10:57:41

相關問題