根据视图将数据发送到意图(单选按钮) [英] sending data to an intent depending on a view (a radio button)

查看:121
本文介绍了根据视图将数据发送到意图(单选按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,显示一个包含单选按钮和一个按钮(确定,取消)的对话框

i have an activity showing a dialog which contains radioButtons, and to buttons (Ok,cancel)

  1. 我可以从此对话框启动活动吗?
  2. 如何将选择的单选按钮的ID发送到第二个活动?

推荐答案

在确定"按钮的onClick()方法中,您可以添加此代码以启动另一个Activity并传​​递选中的单选按钮的ID:

in the onClick() method of the OK Button, you can add this code to start another Activity and pass the id of the checked radio button :

Intent intent = new Intent(FirstActivity.this, SecondActitvity.class);
intent.putextras("extra_selected_radio_button", checkedRadioButton.getId());
startActivity(intent);

以及SecondActivityonCreate()方法中,您可以像这样检索所选单选按钮的ID:

and in the onCreate() method of the SecondActivity , you can retrieve the id of the selected radio button like this :

Intent intent = getIntent();
int radioButtonId = intent.getIntExtra("extra_selected_radio_button", -1); // -1 is the default value

PS:选中教程,以了解有关在Android中的各个活动之间发送数据的更多信息.

PS : Check this tutorial to learn more about sending data between activities in Android.

这篇关于根据视图将数据发送到意图(单选按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆