• GridView 末尾固定两个Item


    今天做到一个添加讨论组成员,需要在最后面显示两个按钮,一个增加人,一个减少人,这样的话就需要在GridView最后面固定一个增加与删除按钮,说一个思路,思路就是在Adapter里面布局的时候,item后面放两个按钮,根据 position 来决定是不是要显示这个按钮,贴一下Adapter里面的代码

    public class MeGroupDetailAdapter extends BaseAdapter {
    private Context context;
    private List<GroupDetailModel.Members> mList = new ArrayList<>();

    public MeGroupDetailAdapter(Context context, List<GroupDetailModel.Members> mList) {
    this.context = context;
    this.mList = mList;
    }

    @Override
    public int getCount() {
    return mList.size() + 2;
    }

    @Override
    public Object getItem(int i) {
    return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
    return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
    ViewHolder vh;
    if (view == null) {
    vh = new ViewHolder();
    view = View.inflate(context, R.layout.item_detail_avator, null);
    vh.mAddPic = (ImageView) view.findViewById(R.id.iv_detail_add);
    vh.mDelPic = (ImageView) view.findViewById(R.id.iv_detail_detele);
    vh.mPic = (ImageView) view.findViewById(R.id.iv_detail_photo);
    vh.mName = (TextView) view.findViewById(R.id.tv_detail_name);
    vh.mLLPerson = (LinearLayout) view.findViewById(R.id.ll_person);
    view.setTag(vh);
    } else {
    vh = (ViewHolder) view.getTag();
    }
    if (i < mList.size()) {
    vh.mAddPic.setVisibility(View.GONE);
    Glide.with(context).load(Constant.URL_PIC + mList.get(i).getAvator()).into(vh.mPic);
    vh.mName.setText(mList.get(i).getNickname());
    } else {
    if (i == mList.size()) {
    //添加按钮
    vh.mAddPic.setVisibility(View.VISIBLE);
    vh.mLLPerson.setVisibility(View.GONE);
    vh.mPic.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    }
    });
    } else {
    //减少按钮
    vh.mDelPic.setVisibility(View.VISIBLE);
    vh.mLLPerson.setVisibility(View.GONE);
    vh.mPic.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    }
    });
    }
    }
    return view;
    }

    private class ViewHolder {
    private TextView mName;
    private ImageView mPic, mAddPic, mDelPic;
    private LinearLayout mLLPerson;
    }
    }
  • 相关阅读:
    Pocket Cube
    善意的投票(最大流)
    清明梦超能力者黄YY(idx数组)
    Inside Triangle
    孤岛营救问题(BFS+状压DP)
    餐巾计划问题(费用流)
    Lunch Time(费用流变型题,以时间为费用)
    71. Simplify Path
    70. Climbing Stairs
    69. Sqrt(x)
  • 原文地址:https://www.cnblogs.com/tyzl/p/6490090.html
Copyright © 2020-2023  润新知