Android:如何从警报对话框启动活动

编程入门 行业动态 更新时间:2024-10-16 02:29:17
本文介绍了Android:如何从警报对话框启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在用户在提醒对话框中选择项目时启动活动。如何获取上下文传递给意图构造函数在下面的代码...

builder.setItems DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int item){ Intent i = new Intent(< WHAT DO I PUT HERE? < new activity> .class); startActivity(i); } });

是使用内部类吗?

解决方案

您可以检索您传递给 AlertDialog.Builder 与 getBaseContext()。 请参阅文档rel=\"nofollow noreferrer\">此处。 / p>

所以这应该工作:

Intent i = new Intent(getBaseContext (),< new activity> .class); startActivity(i);

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:如何从警报对话框启动活动

本文发布于:2023-11-27 10:38:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   对话框   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!