AlertDialog.Builder builder;
final AlertDialog dialog;

final Context mContext = MainActivity.this;

LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
//View layout = inflater.inflate(R.layout.enroll_dialog, (ViewGroup)findViewById(R.id.enroll_layout_root));
View layout = inflater.inflate(R.layout.test_dialog, null);

final EditText enrolleditText = (EditText)layout.findViewById(R.id.test_editText);


builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setPositiveButton(android.R.string.ok, null); //Set to null. We override the onclick
builder.setNegativeButton(android.R.string.cancel, null);
dialog = builder.create();
dialog.show();

//Overriding the handler immediately after show is probably a better approach than OnShowListener as described below
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String getId = enrolleditText.getText().toString();
if (!(getId.isEmpty()))
{
Toast.makeText(mContext,"success",Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
//return;
Toast.makeText(mContext,"insert name",Toast.LENGTH_SHORT).show();
}
}
});

dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});


Posted by 흰털너부리
: