Custom Input Dialog - Android

 

public class InputDialog {

public static String text=null;
private static Context mContext;

public InputDialog(Context context)
{
mContext=context;
}

public static String getText()
{

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Title");

// Set up the input
final EditText input = new EditText(mContext);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT );
builder.setView(input);

// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
text = input.getText().toString();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();
return text;
}

}

Comments