Android 选中时,多个复选框信息将显示在另一个活动中

Android 选中时,多个复选框信息将显示在另一个活动中,android,checkbox,android-activity,checkboxlist,Android,Checkbox,Android Activity,Checkboxlist,我们的问题是我们需要制作某种菜单,在第一个活动中,有一个带有复选框的食物列表 我们要做的是,当单击“确定”按钮时,选中的复选框中的信息将显示在另一个活动中 这是我们的.xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent

我们的问题是我们需要制作某种菜单,在第一个活动中,有一个带有复选框的食物列表

我们要做的是,当单击“确定”按钮时,选中的复选框中的信息将显示在另一个活动中

这是我们的.xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#ffff"
tools:context=".MainMenu" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="@string/dessertsmenu"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="27dp"
    android:text="@string/meal_ok"
    android:onClick="onClickmeal_ok" />

<CheckBox
    android:id="@+id/chkAutosave3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/chkAutosave1"
    android:layout_below="@+id/chkAutosave1"
    android:defaultValue="false"
    android:text="@string/peachcrumbbars"
    android:onClick="onClickpeachcrumbbars_ok"  />

<CheckBox
    android:id="@+id/chkAutosave4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/chkAutosave3"
    android:layout_below="@+id/chkAutosave3"
    android:defaultValue="false"
    android:text="@string/snickerysquares"
    android:onClick="onClicksnicjerysquares_ok"  />

<CheckBox
    android:id="@+id/chkAutosave1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="22dp"
    android:layout_marginTop="18dp"
    android:defaultValue="false"
    android:text="@string/blackberrypiebars"
    android:onClick="onClickblackberrypiebars_ok"  />

要在活动之间传递数据,请使用Intent extra

public void onClickmeal_ok(View view)
{
Intent i = new Intent("com.example.activityname");
i.putExtra("extra1", "this is an extra");
i.putExtra("extra2", 420);
} 
您还可以使用Bundle一次放置多个项目

public void onClickmeal_ok(View view)
{
Intent i = new Intent("com.example.activityname");
Bundle extras = new Bundle();
extras.putInt("extra4", 420);
i.putExtras(extras);
} 
然后,您可以使用

String stringExtra1 = getIntent().getString("extra1");
或者使用

Bundle bundle = getIntent().getExtras();

如果您向社区提供一些关于代码当前问题的见解,您可能会有更好的机会获得帮助。您是否收到任何错误消息?如果是,请用它更新您的问题。hmmm。代码上没有特别的错误。我真的很想学习并知道如何在选中复选框并单击“确定”按钮时在下一个活动中显示复选框的文本或详细信息。假设复选框名称为布丁,然后选中它,然后单击“确定”按钮。所以“布丁”文本应该在下一个活动中显示:)哇。谢谢但是,我们可以在新的.xml文件中添加什么,在该文件中我们将显示选中的复选框?示例第一个复选框名称是可口可乐,第二个复选框名称是百事可乐。如果选中了coke,我们希望新的.xml文件显示:订单列表:coke抱歉,我们在这方面真的很新^^我会在第二个活动的.java文件的OnCreate方法中执行此操作,检索您的额外内容并检查您的值,然后加载您需要的列表
Bundle bundle = getIntent().getExtras();