How to set button click listener for Custom Dialog?

后端 未结 7 426
遇见更好的自我
遇见更好的自我 2021-01-11 11:30

I have made a main Dialog class on which I send the layout ID and shows the layout as a Dialog now when I send the layout from calling class it pop

相关标签:
7条回答
  • 2021-01-11 12:25
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
    
        builder.setIcon(R.drawable.warning);
        builder.setTitle("Warning");
    
        final LinearLayout backAlarmDialogLayout = (LinearLayout) getLayoutInflater()
                .inflate(R.layout.custumedialog_layou, null);
        builder.setView(backAlarmDialogLayout);
        builder.setCancelable(true);
        backAlarmDialog = builder.create();
    

    Set these codes to initialize your costumed dialog in onCreate like this, and if you would like to add listener to your button, you can write another method like

      public void onClickCancel(View view){
        backAlarmDialog.dismiss();
    }
    

    then you use

    android:onClick="onClickCancel"
    

    in the button in the XML.files you have costumed the dialog, I have tried other ways but they just would not work and I don not know why is this.Maybe someone would solve mine. ||= =

    0 讨论(0)
提交回复
热议问题