我有一个列表视图从SqLite Db中获取数据。我需要在列表视图中获取正在单击的数据,并将其显示在另一个列表视图中的活动中。将数据从ListView传递到另一个Listview
我尝试过使用共享偏好设置,但我一次只能获取一个数据,并将其作为textview显示在另一个活动中。
我不知道如何全部显示在列表视图中选择的数据或从选定的数据创建列表视图,需要帮助。
我的搜索活动
listContent1.setAdapter(cursorAdapter);
listContent1.setOnItemClickListener(listContentOnItemClickListener);
private ListView.OnItemClickListener listContentOnItemClickListener = new ListView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
String item_content1 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_FOODNAME));
String item_content2 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_CALORIES));
arlene = arlene + Integer.parseInt(item_content2);
String item = String.valueOf(" Food Name: " + item_content1) + "\n" +
" Calories: " + item_content2;
Toast.makeText(Search.this, item, Toast.LENGTH_LONG).show();
food.setText(item_content1);
calories.setText(String.valueOf(arlene));
Intent myIntent = new Intent(Search.this, Foodlog.class);
Bundle bundle = new Bundle();
bundle.putString("SQLITEDATA1", food.getText().toString());
bundle.putString("SQLITEDATA2", calories.getText().toString());
myIntent.putExtras(bundle);
startActivity(myIntent);
}
这里是我的foodlog活动
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.foodlog);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
foodnum = (TextView)findViewById(R.id.foodNum);
remaining = (TextView)findViewById(R.id.remainingNum);
totalnum = (TextView)findViewById(R.id.totalNum);
foodlog = (ListView)findViewById(R.id.list);
Bundle bundle = getIntent().getExtras();
if(bundle != null){
String food = bundle.getString("SQLITEDATA1");
String calories = bundle.getString("SQLITEDATA2");
String[] values = new String[] { food, calories }; //That you got from your intent bundle
LVAdapter adapter = new LVAdapter(this, R.layout.foodlist, values);
setListAdapter(adapter);
}
希望你能帮助我
03-04 23:40:18.572: E/AndroidRuntime(451): FATAL EXCEPTION: main
03-04 23:40:18.572: E/AndroidRuntime(451): java.lang.RuntimeException: Unable to start activity ComponentInfo{me.mojica.caloriewatch/me.mojica.caloriewatch.Foodlog}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.os.Looper.loop(Looper.java:123)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-04 23:40:18.572: E/AndroidRuntime(451): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 23:40:18.572: E/AndroidRuntime(451): at java.lang.reflect.Method.invoke(Method.java:521)
03-04 23:40:18.572: E/AndroidRuntime(451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-04 23:40:18.572: E/AndroidRuntime(451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-04 23:40:18.572: E/AndroidRuntime(451): at dalvik.system.NativeStart.main(Native Method)
03-04 23:40:18.572: E/AndroidRuntime(451): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
03-04 23:40:18.572: E/AndroidRuntime(451): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.Activity.setContentView(Activity.java:1647)
03-04 23:40:18.572: E/AndroidRuntime(451): at me.mojica.caloriewatch.Foodlog.onCreate(Foodlog.java:22)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-04 23:40:18.572: E/AndroidRuntime(451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
我已经根据答案编辑此。我仍然无法运行。请帮助。
附加一个“捆绑”与“意图”进行第二次活动。 – 2013-03-03 19:53:34
我尝试过,但我怎么能从它创建一个列表视图?请帮帮我。 – 2013-03-03 19:55:15
我会帮助你,你首先将你的问题放在哪里? – 2013-03-03 19:57:44