仅在用户单击AlertDialog上的“确定"后才如何启动活动? [英] How to start activity only after user clicks 'ok' on AlertDialog?

查看:71
本文介绍了仅在用户单击AlertDialog上的“确定"后才如何启动活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我创建了一个包含列表视图的布局.我添加了一个按钮``+'',单击该按钮将显示一个带有编辑文本框和两个选项的确定和取消按钮的警报框.
我想将用户在编辑文本框中输入的项目添加到列表视图中.有人可以帮我添加吗?



这是向我显示警报"对话框的代码:

if(v.getId()== addbtn.getId())
{
AlertDialog.Builder alert =新的AlertDialog.Builder(this);

alert.setTitle(添加新位置");


//设置EditText视图以获取用户输入
最终的EditText输入=新的EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok",新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton){
可修改的值= input.getText();
//做有价值的事情!
}
});

alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton){
//已取消.
}
});

alert.show();



}

Hi,
I have created an layout which contains the listview. I have added a button''+'', which on clicked gives an alert box with an edit text box and two options OK and CANCEL.
I want to add the item which the user enters in the edit text box into the listview. Can any one help me out how to add it?



this is the code which shows me the Alert dialogue box:

if(v.getId() == addbtn.getId())
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Add new location");


// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
// Do something with value!
}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});

alert.show();



}

推荐答案

使用确认"窗口而不是警告"窗口.

谢谢,
Ambesha
Use "confirm" window instead of "alert" window.

Thanks,
Ambesha


这篇关于仅在用户单击AlertDialog上的“确定"后才如何启动活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆