我正在尝试调试某些内容,并希望弹出一个消息对话框.Eclipse告诉我它要"创建方法showAlert(string,string,string,boolean)"
我导入了这个导入android.content.DialogInterface;
我错过了什么步骤?
如果您尝试创建并显示AlertDialog,则应该使用AlertDialog.Builder.
DialogInterface,顾名思义,是一个接口,只有2个方法:cancel()和dismiss().
创建AlertDialog非常简单:
new AlertDialog.Builder(this)
.setTitle("Some Title")
.setMessage("some message")
.setPositiveButton("OK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
})
.setNegativeButton("cancel", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when cancel got clicked
}
})
.show();
Run Code Online (Sandbox Code Playgroud)
这显示了一个简单的AlertDialog.
提示:检查Activity.showDialog(int)和Activity.onCreateDialog(),它们使您在使用对话框时的生活更轻松.
如果您只显示调试消息,可以尝试Toast.makeText():
Toast.makeText(context, "Hi there!", Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
别忘了打电话show().
| 归档时间: |
|
| 查看次数: |
11536 次 |
| 最近记录: |