今天做到一个添加讨论组成员,需要在最后面显示两个按钮,一个增加人,一个减少人,这样的话就需要在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;
}
}
posted on 2017-03-02 13:21  依米妮  阅读(309)  评论(0编辑  收藏  举报