ADD file via upload

master
pa3fjc76b 3 years ago
parent f6c6df8710
commit c52b86c1f0

@ -0,0 +1,65 @@
package com.example.health.food_grid;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.health.Bean.FoodBean;
import com.example.health.R;
import java.util.List;
public class FoodGridAdapter extends BaseAdapter {
Context context;
public FoodGridAdapter(Context context, List<FoodBean> mDates) {
this.context = context;
this.mDates = mDates;
}
List<FoodBean>mDates;
@Override
public int getCount() {
return mDates.size();
}
@Override
public Object getItem(int position) {
return mDates.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//声明ViewHolder
ViewHolder holder = null;
if (convertView == null) {//判断是否有复用的view如果没有就创建
convertView = LayoutInflater.from(context).inflate(R.layout.item_foodgrid,null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
//获取指定位置的数据
FoodBean foodBean = mDates.get(position);
holder.iv.setImageResource(foodBean.getPicID());
holder.tv.setText(foodBean.getFoodName());
return convertView;
}
class ViewHolder{
ImageView iv;
TextView tv;
public ViewHolder(View view){
iv=view.findViewById(R.id.item_grid_iv);
tv=view.findViewById(R.id.item_grid_tv);
}
}
}
Loading…
Cancel
Save