2012-07-06 28 views
3

如何在我的應用程序中添加第3個按鈕......我想將第三個按鈕設置爲「收聽」....我已經檢查如何在我的應用程序中添加第3個按鈕

.setNeutralButton 

但它不工作....它怎麼可能?

public class MessageViewPage extends Activity { 

ScrollView sv; 
String nickname,body; 
private LinearLayout mainLayout; 
final Context context = this; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.message_view_page); 

    Bundle b = getIntent().getExtras(); 

    nickname= b.getString("nick"); 
    body=b.getString("body"); 

    System.out.println(nickname); 
    System.out.println(body); 

    mainLayout=(LinearLayout)findViewById(R.id.mainLayoutmess); 

    mainLayout.setOnClickListener(new OnClickListener() { 

     public void onClick(View arg0) { 

      System.out.println("***************in on click************"); 

      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        context); 

       // set title 
       alertDialogBuilder.setTitle("Access"); 

       // set dialog message 
       alertDialogBuilder 
        .setMessage("What's next?") 
        .setCancelable(false) 
        .setPositiveButton("Reply",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 

          Intent i=new Intent(MessageViewPage.this,Reply.class); 
          startActivity(i); 
          finish(); 

         } 
         }) 
        .setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 

          dialog.cancel(); 

         } 
        }); 


        // create alert dialog 
        AlertDialog alertDialog = alertDialogBuilder.create(); 

        // show it 
        alertDialog.show(); 



} 
}); 



} 



} 

與.setNeutralButton ........具有錯誤

enter image description here

而不.setNeutralButton ....沒有錯誤

enter image description here

+1

你需要的是一個自定義對話框。 下面是如何把它做[http://stackoverflow.com/questions/5544405/android-custom-dialog][1] [1]:http://stackoverflow.com/questions/5544405/android-custom-dialog – the100rabh 2012-07-06 11:36:59

+1

將此鏈接指向自定義對話框http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog,tis one for question http://www.androidhive.info/2011/09 /如何顯示警報對話框在android/ – KMI 2012-07-06 11:39:05

+0

通過定義**自定義對話框**,你可以有多達你想要的按鈕。 – 2012-07-06 11:40:40

回答

3

JUST除去分號(;) setNegativeButton's OnClickListener .add as:

alertDialogBuilder 
        .setMessage("What's next?") 
        .setCancelable(false) 
        .setPositiveButton("Reply",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 

          Intent i=new Intent(MessageViewPage.this,Reply.class); 
          startActivity(i); 
          finish(); 

         } 
         }) 
        .setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 

          dialog.cancel(); 

         } 
        }) // ; remove this semicolon here 
.setNeutralButton("Neutral",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 

          dialog.cancel(); 

         } 
        }); 
2

刪除分號; setNegativeButton之後的。然後你可以添加NeutralButton。

-1

試試這個....

AlertDialog alert=new AlertDialog.Builder(adminpage.this).create(); 

現在嘗試設置按鈕,您將得到三個按鈕

相關問題