2014-11-04 33 views

回答

1

只需將新按鈕添加到您的XML文件,並獲得該按鈕的ID,並將點擊偵聽器放在這個按鈕上。 這是爲我工作。

+3

你的回答可能對他有幫助。所以只需添加一部分代碼作爲答案。 – Piyush 2014-11-04 11:16:51

+1

爲什麼沒有代碼在這和andwer – 2014-11-04 11:17:35

+0

,一個爲我工作 – 2014-11-04 11:31:03

0
LayoutInflater factory = LayoutInflater.from(Splash.this); 
    final View textEntryView = factory.inflate(R.layout.text_entry, null); 

    //text_entry is an Layout XML file containing two text field to display in alert dialog 

    final EditText input1 = (EditText) textEntryView.findViewById(R.id.editText1); 
    final EditText input2 = (EditText) textEntryView.findViewById(R.id.editText2);    
        input1.setHint("roomnumber"); 
        input2.setHint("hotelname"); 
        AlertDialog.Builder alert = new AlertDialog.Builder(Splash.this); 

        alert.setIcon(android.R.drawable.ic_menu_info_details) 
          .setTitle("Enter the Text:") 
          .setView(textEntryView) 
          .setPositiveButton("Your Default button text", 
           new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int whichButton) { 
             Log.i("AlertDialog","TextEntry 1 Entered "+input1.getText().toString()); 
             Log.i("AlertDialog","TextEntry 2 Entered "+input2.getText().toString()); 
             if(isOnline()) 
             {  
             /* User clicked OK so do some stuff */ 

            }else{ 


            } 
            } 
           }); 

        alert.show(); 
0

這將解決您的問題! 您需要將onclick監聽器設置爲對話框中的所有按鈕。按照下面的代碼。

public void showDialogWithIcons() { 
      final Dialog dialog = new Dialog(this); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.icons_dialog); 

      dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0)); 

      Button yesButton = (Button) dialog.findViewById(R.id.yesanswer_icons); 
      yesButton.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 

        TextView tvForIconToChange = (TextView) findViewById(R.id.textInThePicture); 
        tvForIconToChange.setTypeface(tf); 
        tvForIconToChange.setText(getMyTextForIcon()); 
        dialog.dismiss(); 

       } 

      }); 
      dialog.show(); 
     } 
0

因爲它的自定義佈局。 要使用按鈕自定義對話框中,定義在烏拉圭回合自定義佈局XML按鈕,然後在代碼中做到這一點:

Button xyz = (Button)dialog.findViewbyId(R.id.abc) 
xyz.setOnClickListener(this or new View.OnClickListener) 
相關問題