Build a dialog I’d like add a listener, but the app crashes.What is wrong?
private void Info(){
textview = (TextView) findViewById(R.id.textView1);
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.info, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view).create().show();
buttonInfo = (Button)findViewById(R.id.buttonInfo);
buttonInfo.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
I guess that the button is inside your dialog’s layout.
If it’s the case, try to replace
by
And you need to store the created AlertDialog (instead of the Builder) if you want to dismiss it after: