1 AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
2 alertDialog.setTitle("PASSWORD");
3 alertDialog.setMessage("Enter Password");
4
5 final EditText input = new EditText(MainActivity.this);
6 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
7 LinearLayout.LayoutParams.MATCH_PARENT,
8 LinearLayout.LayoutParams.MATCH_PARENT);
9 input.setLayoutParams(lp);
10 alertDialog.setView(input);
11 alertDialog.setIcon(R.drawable.key);
12
13 alertDialog.setPositiveButton("YES",
14 new DialogInterface.OnClickListener() {
15 public void onClick(DialogInterface dialog, int which) {
16 password = input.getText().toString();
17 if (password.compareTo("") == 0) {
18 if (pass.equals(password)) {
19 Toast.makeText(getApplicationContext(),
20 "Password Matched", Toast.LENGTH_SHORT).show();
21 Intent myIntent1 = new Intent(view.getContext(),
22 Show.class);
23 startActivityForResult(myIntent1, 0);
24 } else {
25 Toast.makeText(getApplicationContext(),
26 "Wrong Password!", Toast.LENGTH_SHORT).show();
27 }
28 }
29 }
30 });
31
32 alertDialog.setNegativeButton("NO",
33 new DialogInterface.OnClickListener() {
34 public void onClick(DialogInterface dialog, int which) {
35 dialog.cancel();
36 }
37 });
38
39 alertDialog.show();
40 }
41
42 });
43
1final View view = layoutInflater.inflate(R.layout.xml_file_created_above, null);
2AlertDialog alertDialog = new AlertDialog.Builder(ct).create();
3alertDialog.setTitle("Your Title Here");
4alertDialog.setIcon("Icon id here");
5alertDialog.setCancelable(false);
6Constant.alertDialog.setMessage("Your Message Here");
7
8
9final EditText etComments = (EditText) view.findViewById(R.id.etComments);
10
11alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() {
12 @Override
13 public void onClick(DialogInterface dialog, int which) {
14
15 }
16});
17
18
19alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new OnClickListener() {
20 @Override
21 public void onClick(DialogInterface dialog, int which) {
22 alertDialog.dismiss()
23 }
24});
25
26
27alertDialog.setView(view);
28alertDialog.show();