问题描述
- 各位大神,这里应该怎么写
-
mGirdView.setAdapter(mImgAdapter);下面是ImageAdapter代码
public class ImageAdapter extends BaseAdapter
{
private static Set mSeletedImg = new HashSet();
private String mDirPath;
private ListmImgPaths;
private LayoutInflater mInflater;public ImageAdapter(Context context,List<String> mDatas,String dirPath) { this.mDirPath = dirPath; this.mImgPaths = mDatas; mInflater = LayoutInflater.from(context); } @Override public int getCount(){ return mImgPaths.size(); } @Override public Object getItem(int position) { return mImgPaths.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position,View convertView,ViewGroup parent) { final ViewHolder viewHolder; if(convertView == null) { convertView = mInflater.inflate(R.layout.item_gridview,parent,false); viewHolder = new ViewHolder(); viewHolder.mImg = (ImageView)convertView.findViewById(R.id.id_item_image); viewHolder.mSelect = (ImageButton)convertView.findViewById(R.id.id_item_select); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder)convertView.getTag(); } viewHolder.mImg.setImageResource(R.drawable.pictures_no); viewHolder.mSelect.setImageResource(R.drawable.picture_unselected); viewHolder.mImg.setColorFilter(null); ImageLoader.getInstance(3, Type.LIFO).loadImage( mDirPath + "/" + mImgPaths.get(position),viewHolder.mImg); final String filePath = mDirPath + "/" + mImgPaths.get(position); viewHolder.mImg.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(mSeletedImg.contains(filePath)) { mSeletedImg.remove(filePath); viewHolder.mImg.setColorFilter(null); viewHolder.mSelect.setImageResource(R.drawable.picture_unselected); } else { mSeletedImg.add(filePath); viewHolder.mImg.setColorFilter(Color.parseColor("#77000000")); viewHolder.mSelect.setImageResource(R.drawable.pictures_selected); } } }); if(mSeletedImg.contains(filePath)) { viewHolder.mImg.setColorFilter(Color.parseColor("#77000000")); viewHolder.mSelect.setImageResource(R.drawable.pictures_selected); } return convertView; } private class ViewHolder { ImageView mImg; ImageButton mSelect; }
}拜托各位大神了
时间: 2024-10-26 02:31:54