csh_34 于 2012.10.16 14:53 提问
- Android中显示提醒对话框问题
-
我想实现一个弹出窗口“确定要删除该项目吗?”
或者点击按钮删除。
如果我点击确认按钮,该项就删除了。
我用代码写了点击按钮的监听器,但不知道用什么来调用对话框或者弹出菜单,来实现这个功能…
-
- yongyong_21 2012.10.16 15:45
- 已采纳
你可以使用alert builder:
new AlertDialog.Builder(this)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
-
- curie_87 2012.10.16 16:28
@Override
protected Dialog onCreateDialog(int id)
{
switch(id)
{
case 0:
{
return new AlertDialog.Builder(this)
.setMessage("set Message here")
.setPositiveButton("set button text here", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1)
{
try
{
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), "", Toast.LENGTH_LONG).show();
}
}
}).create();
}
}
return null;
}
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!