如何一次又一次调用同一警报对话框? [英] How to call same alert Dialog again and again?
问题描述
我创建了一个警报对话框
,其中有两个 EditText
和两个 Button
,然后获取 EditText
的值,如果值匹配,那么我正在执行一些操作,否则我想调用相同的 AlertDialog
。如果值不同,则无法调用相同的警报对话框。我不知道我在哪里做错了...
I have create one Alert Dialog
which have two EditText
and two Button
and I fetch the value of the EditText
and if value matches then I am doing some operation otherwise I want to call same AlertDialog
again.But if value differs then I am not able to call the same alert dialog.I don't know where i am doing wrong...
我的代码就像这样::
My Code goes like this ::
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;
}
}
希望我的问题很清楚…… 。
请帮助我..
在此先感谢.....:)
Hope my question is clear....... Please help me .. Thanks in Advance ..... :)
推荐答案
I知道这个软件迟到了。但是对于未来的追求者。
我遇到了同样的问题,没有与.hide().show()和.dismiss()的组合不起作用。
I know this answare is late. But for the future seekers. I had the same problem and no combination with .hide() .show() and .dismiss() doesn't react. Probably the system need some time and then it is working fine.
if (!SDCartConnected())
{
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
public void run() {
showDialog(Const.DIALOG_SDCARD_MISSING);}}, 2000);
}
这篇关于如何一次又一次调用同一警报对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!