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
dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");
Button dialog_btn = (Button) dialog.findViewById(R.id.dialog_button);
dialog_btn.setOnClickListener(new View.OnClickListener()
{
// Perform button logic
}
There you go:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(id);
Button signInbutton=(Button)findViewById(R.id.signInButton);
signInButton.setOnClickListener(this);
Button closebutton=(Button)findViewById(R.id.closeButton);
closeButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(R.id.closeButton == v.getId()) {
closeButton(v);
} else {
// do the same for signInButton
}
}
Suggest you learn the basic beforehand.
dialog_bring_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
final Dialog dialog = new Dialog(MyActivity.this);
dialog.setContentView(R.layout.MyCustomDialogxmlfile);
dialog.show();
/* My Cancel Button , and its listener */
my_cancel_btn=(Button)dialog.findViewById(R.id.datesetbtn);
my_cancel_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
I find that the code is clearer to seperate my click handlers. Add this in the onCreate method:
signInbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do stuff for signInButtonClick
}
});
// same for other button
In 2019 this work for me. You can change text view with button.
Dialog mdialog = new Dialog(this);
mdialog.setContentView(R.layout.activity_select_type);
mdialog.show();
TextView view = mdialog.findViewById(R.id.viewQuotes);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Working...", Toast.LENGTH_SHORT).show();
}
});
submit.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
CustomDialog dialog1 = new CustomDialog(Classname.this);
dialog1.setContentView(R.layout.submitdialog);
dialog1.setTitle(" SUBMIT :");
TextView text = (TextView) dialog1.findViewById(R.id.message);
text.setText(" Your Answer is correct ");
}
}