0
我们想要做的是将Desserts Menu中的选中复选框的信息显示到最终订单列表(LOFO)活动中。如何在点击这些复选框时在另一个活动中显示多个复选框信息?
这里是我们的desserts.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="onClicdesserts_ok" />
<CheckBox
android:id="@+id/chkpeach"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkpie"
android:layout_below="@+id/chkpie"
android:defaultValue="false"
android:text="@string/peachcrumbbars"
android:onClick="onClickpeachcrumbbars_ok" />
<CheckBox
android:id="@+id/chksquares"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkpeach"
android:layout_below="@+id/chkpeach"
android:defaultValue="false"
android:text="@string/snickerysquares"
android:onClick="onClicksnicjerysquares_ok" />
<CheckBox
android:id="@+id/chkpie"
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" />
这里是我们的DessertsMenu.java:
package net.xadtv.yoursmenu;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class DessertsMenu extends Activity{
Button button1;
CheckBox chkpie;
CheckBox chkpeach;
CheckBox chksquares;
public static final String MENU_NAME = "MyMenuFile";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.desserts);
button1 = (Button) findViewById(R.id.button1);
chkpie = (CheckBox) findViewById(R.id.chkpie);
chkpeach = (CheckBox) findViewById(R.id.chkpeach);
chksquares = (CheckBox) findViewById(R.id.chksquares);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(chkpie.isChecked());
SharedPreferences settings1 = getSharedPreferences(MENU_NAME, 0);
SharedPreferences.Editor pie = settings1.edit();
pie.putString("pietext", "black berry pie bars");
pie.commit();
if(chkpeach.isChecked());
SharedPreferences settings2 = getSharedPreferences(MENU_NAME, 0);
SharedPreferences.Editor peach = settings2.edit();
peach.putString("peachtext", "peach crumbbars");
peach.commit();
if(chksquares.isChecked());
SharedPreferences settings3 = getSharedPreferences(MENU_NAME, 0);
SharedPreferences.Editor squares = settings3.edit();
squares.putString("squarestext", "snickery squares");
squares.commit();
Intent intent = new Intent(getApplicationContext(),LOFO.class);
startActivity(intent);
}
});
}
}
这是我们希望把点击复选框的信息,该最终订单活动清单。
这里是我们的lofo.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="#277c9b"
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="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView4"
android:layout_below="@+id/textView4"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView5"
android:layout_below="@+id/textView5"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
这里是我们的LOFO.java:
package net.xadtv.yoursmenu;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class LOFO extends Activity{
public static final String MENU_NAME = "MyMenuFile";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lofo);
TextView tvpeach = (TextView)findViewById(R.id.textView1);
TextView tvsquares = (TextView)findViewById(R.id.textView2);
TextView tvpie = (TextView)findViewById(R.id.textView3);
SharedPreferences settings1 = getSharedPreferences(MENU_NAME, 0);
SharedPreferences settings2 = getSharedPreferences(MENU_NAME, 0);
SharedPreferences settings3 = getSharedPreferences(MENU_NAME, 0);
tvpeach.setText(settings1.getString("peach", ""));
tvsquares.setText(settings2.getString("squares", ""));
tvpie.setText(settings3.getString("pie", ""));
}
}
现在的问题是,一旦我们运行它,然后选一的复选框,会发生错误(Source not Found)。
任何帮助,非常感谢。 :)
张贴堆栈跟踪/ logcat的输出吧。和行号相关。 – cbrulak