Here is how to make an alertDialog that contains a field where user will enter some value…This filed is an EditText.
final FrameLayout fl = new FrameLayout(Main.this); final EditText input = new EditText(Main.this); input.setGravity(Gravity.CENTER); fl.addView(input, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); input.setText("DefaultMSG"); input.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { if (input.getText().toString().compareTo("Anonymous")==0) { input.setText("");//here we set text to empty if user tap on the EditText and want to modify the text } }}); AlertDialog.Builder builder = new AlertDialog.Builder(Main.this); //building the custom AlertDialog builder.setView(fl) .setTitle("Enter your name: ") .setPositiveButton("OK", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface d, int which) { Intent q=new Intent(Main.this,SinglePlayer.class); q.putExtra("keyName",input.getText().toString()); startActivity(q); //here i have sent to the next Activity the value that user just entered in the EditText field, and also i have lunched that Activity d.dismiss(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface d, int which) { d.dismiss(); } }).create().show(); }});
I hope this Custom AlertDialog Tutorial with an Edit text helped you, and i wait your comments.