我可以从我的 in 中填充我ListView
的项目。现在我想点击一个项目(里面共有 8 个项目)并转到一个名为的新活动并显示它的所有营养成分。SQLiteDatabase
lunch.java
ListView
Display.java
编辑后
午餐.java:
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
switch(pos)
{
case 0 :
String mealName = (String) parent.getItemAtPosition(pos);
Cursor cursor = dbopener.getBreakfastDetails(mealName);
cursor.moveToNext();
id = cursor.getLong(cursor.getColumnIndex(mealName));
String message = cursor.getString(1) + "\n" + cursor.getInt(2);
Intent event1 = new Intent("com.edu.tp.iit.mns.Display");
event1.putExtra("name", id);
startActivity(event1);
break;
显示.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
TextView tv = (TextView) findViewById(R.id.tvfoodName);
Intent intent = getIntent();
long id = intent.getLongExtra("name", -1);
if(id == -1){
return;
}
tv.setText(-1);
}