我创建了一个Alert Dialog
具有两个EditText
和两个Button
的值,并且我获取了的值,EditText
如果值匹配,那么我正在执行一些操作,否则我想再次调用相同AlertDialog
的值。但是如果值不同,那么我无法调用相同的警报对话框。我不知道我在哪里做错了......
我的代码是这样的::
public class MainActivity extends Activity
{
private Button btn_click;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_click=(Button)findViewById(R.id.btn_click);
btn_click.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
showDialog(0);
}
});
}
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case 0:
// This example shows how to add a custom layout to an AlertDialog
android.app.AlertDialog.Builder login = new android.app.AlertDialog.Builder(this);
try
{
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.login_dialog, null);
final EditText username_alert = (EditText) textEntryView.findViewById(R.id.username);
final EditText password_alert = (EditText) textEntryView.findViewById(R.id.password);
login.setTitle("Login").setIcon(R.drawable.ic_launcher).setView(textEntryView)
.setPositiveButton("Login", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
/* User clicked OK so do some stuff */
String uname_alert=username_alert.getText().toString();
String pass_alert=password_alert.getText().toString();
if(uname_alert.equals("aaaa") && pass_alert.equals("aaaa"))
{
//do Something........
}
else
{
showDialog(0);
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
/* User clicked cancel so do some stuff */
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
return login.create();
}
return null;
}
}
希望我的问题很清楚......请帮助我..在此先感谢...... :)