package com.example.health.food_grid; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.example.health.Bean.FoodBean; import com.example.health.R; public class FoodDescActivity extends AppCompatActivity { TextView name,cal,note; ImageView return1,pic; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_food_desc); //使用下面的函数获取到dexc的布局的控件 initView(); //接收上一级页面传来的数据 Intent intent = getIntent(); //序列化 FoodBean foodBean = (FoodBean) intent.getSerializableExtra("food"); //设置显示控件 name.setText(foodBean.getFoodName()); cal.setText(foodBean.getFoodCalorie()); note.setText(foodBean.getFoodIntroduce()); pic.setImageResource(foodBean.getPicID()); } private void initView() { name = findViewById(R.id.fooddexc_tv_name); cal = findViewById(R.id.fooddesc_tv_cal); note = findViewById(R.id.fooddesc_tv_note); return1 = findViewById(R.id.fooddesc_iv_return); pic = findViewById(R.id.fooddesc_iv_pic); return1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish();//销毁当前的activity } }); } }