先简单看一下效果,ui效果可能不是很好,凑活着看:
GridView 与 加号的实现(啰嗦代码就不看了)
主要看适配器怎么写
public int getCount() {
return photos.size() +1;//返回listiview数目加1(目的是为了手动将加号以item的形式加入)
}
public Object getItem(intposition) {
return position;
}
public long getItemId(intposition) {
return position;
}
public View getView(intposition, View convertView, ViewGroup parent) {
ViewHolder holder =null;
if(convertView ==null) {
holder =newViewHolder();
convertView = LayoutInflater.from(Context).inflate(R.layout.grid_item_select
, parent,false);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.imageView= (ImageView) convertView.findViewById(R.id.iv_kinder_image);//返回的照片item
holder.imageView1= (ImageView) convertView.findViewById(R.id.iv_kinder_image1);
if(position <photo.size()) //添加返回来的照片数组
Glide.with(XddApp.context)
.load(newFile(photos.get(position)))
.fitCenter()
.into(holder.imageView);
holder.imageView.setVisibility(View.VISIBLE);
holder.imageView1.setVisibility(View.GONE);
}else{
// 手动添加一个Item(即加号)
holder.imageView.setVisibility(View.GONE);
holder.imageView1.setVisibility(View.VISIBLE);
//点击进入选择照片界面
holder.imageView1.setOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View v) {
Intent intent =newIntent(XddApp.context, GridPhonePhotoActivity.class);
intent.putStringArrayListExtra("photos",photos);
((UploadKindergartenActivity)mContext).startActivityForResult(intent,idType);
}
});
}
returnconvertView;
}
static classViewHolder {
publicImageViewimageView;
publicImageViewimageView1;
}