我需要当用户选择在警告对话框中的项目启动活动。我如何获得上下文传递给意向构造以下code ...
I need to start an activity when the user chooses an item in an alert dialog. How do I get the context to pass to the intent constructor in the following code...
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Intent i = new Intent(<WHAT DO I PUT HERE?>, <new activity>.class);
startActivity(i);
}
});
它是采用内部类的?有什么想法?
Is it the use of the inner class?? Any thoughts?
您可以检索你传递给 AlertDialog.Builder
与 getBaseContext上下文()
。
查看文档here.
You can retrieve the context you have passed to AlertDialog.Builder
with getBaseContext()
.
See the doc here.
所以,这应该工作:
Intent i = new Intent(getBaseContext(), <new activity>.class);
startActivity(i);