本文介绍了Android:如何从警报对话框中启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在警报对话框中选择项目时,我需要开始一个活动。如何使上下文在以下代码中传递给intent构造函数...
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 with getBaseContext()。 请参阅文档此处。
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);更多推荐
Android:如何从警报对话框中启动活动
发布评论