0
改變我的代碼後(first attempt)我有一個類似的問題。我更新了我的getView()以執行正確的方式。StateListDrawable GridView內
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Resources res = activity.getResources();
if(convertView == null) {
LayoutInflater vi = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.video_gallery_item, parent, false);
}
Bitmap bmp = getBitmap(videoIds[ position ]);
/* This layer drawable will create a border around the image. This works */
Drawable[] layers = new Drawable[ 2 ];
layers[ 0 ] = new BitmapDrawable(res, bmp);
layers[ 1 ] = res.getDrawable(R.drawable.border_selected);
LayerDrawable layerDrawable = new LayerDrawable(layers);
/* Create the StateListDrawable */
StateListDrawable drawable = new StateListDrawable();
drawable.addState(StateSet.WILD_CARD, new BitmapDrawable(res, bmp));
drawable.addState(new int[]{ android.R.attr.state_checked, android.R.attr.state_selected }, layerDrawable);
ImageView v = (ImageView)convertView.findViewById(R.id.image);
v.setImageDrawable(drawable);
v.setAdjustViewBounds(true);
thumbnails[ position ] = bmp;
return convertView;
}
此適配器是一個GridView稱爲videoGallery使用:
videoGallery.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
videoGallery.setMultiChoiceModeListener(new MultiChoiceModeListener() { ... }
我遇到的問題是,當他們在GridView上通過長按選擇的圖像不會改變。操作欄更改,我的上下文菜單出現等。我也嘗試通過XML創建StateListDrawable,結果相同。思考?
UPDATE
在我getView更改
drawable.addState(new int[]{ android.R.attr.state_checked, android.R.attr.state_selected }, layerDrawable);
到
drawable.addState(StateSet.WILD_CARD, layerDrawable);
()顯示我正在尋找的邊界。所以也許StateListDrawable沒有得到狀態改變?任何人有任何想法?