在第一个SearchShowActivity.java里:
HashMap<String,Object> itemMap = (HashMap<String, Object>) adapterView.getItemAtPosition(position);
//int num = (Integer) itemMap.get("id");
String foodName = (String) itemMap.get("foodName");
String classification = (String) itemMap.get("foodClassification");
String describe = (String) itemMap.get("describe");
DBFood food = new DBFood();
//food.setId(num);
food.setFoodName(foodName);
food.setFoodClassification(classification);
food.setDescribe(describe);
intent.putExtra("food", food);
intent.setClass(SearchShowActivity.this, LookupMenuActivity.class); //跳转到显示的页面
SearchShowActivity.this.startActivity(intent);
第二个LookupMenuActivity.java里:
textViewN = (TextView) findViewById(R.id.show_name_t); //xml里定义了show_name_t、show_classification_t、show_describe_t用来显示结果
textViewC = (TextView) findViewById(R.id.show_classification_t);
textViewD = (TextView) findViewById(R.id.show_describe_t);
Intent intent = this.getIntent();
DBFood food = (DBFood) intent.getSerializableExtra("food"); //将SearchShowActivity.java中打包传过来的food接受。
textViewN.setText(food.getFoodName()); //将food传来的名字、类型、描述与显示结果的textview绑定,显示在上面。
textViewC.setText(food.getFoodClassification());
textViewD.setText(food.getDescribe());