本文介绍了Android:如何从警报对话框启动 Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
解决方案
You can retrieve the context you have passed to AlertDialog.Builder
with getBaseContext()
.
See the doc here.
So this should work:
Intent i = new Intent(getBaseContext(), <new activity>.class);
startActivity(i);
这篇关于Android:如何从警报对话框启动 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!