1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| package com.gallifrey.dialogtestapplication;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.Button;
public class MainActivity extends AppCompatActivity { private Button mBtnCustom; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
mBtnCustom=findViewById(R.id.btn_custom);
mBtnCustom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view= LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_custom,null,false); AlertDialog.Builder customDialog=new AlertDialog.Builder(MainActivity.this); Button customBtn1=view.findViewById(R.id.custom_btn1); Button customBtn2=view.findViewById(R.id.custom_btn2); customDialog.setView(view).show(); customBtn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent=new Intent(MainActivity.this,SecondActivity.class); startActivity(intent); } });
customBtn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); } }); }
}
|