0
我有一個GridView與自定義適配器,當我從列表中選擇一個項目時,選擇器顯示一秒鐘並消失。我想自定義適配器導致它,我試着玩它和選擇器,但無濟於事。List/GridView中的選擇器不顯示
這裏是我的適配器(基於 「你好,查看」 網格視圖樣品):
package shira.android.paintdroid;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
class PaintActionsAdapter extends BaseAdapter
{
private Context context;
private int[] actionsImagesResources;
public PaintActionsAdapter(Context context)
{
if (context==null)
throw new IllegalArgumentException("The context must be non-null!");
this.context=context;
/*actionsImagesResources=context.getResources().getIntArray(R.array.
actions_images);*/
actionsImagesResources=new int[6];
for (int counter=0;counter<actionsImagesResources.length;counter++)
actionsImagesResources[counter]=R.drawable.pencil;
}
public int getCount() { return actionsImagesResources.length; }
public long getItemId(int position)
{ return actionsImagesResources[position]; }
public Object getItem(int position)
{ return actionsImagesResources[position]; }
public View getView(int position,View convertView,ViewGroup parent)
{
ImageView actionImageView;
if (convertView==null)
{
actionImageView=new ImageView(context);
AbsListView.LayoutParams layoutParams=new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.
FILL_PARENT);
actionImageView.setLayoutParams(layoutParams);
//actionImageView.setAlpha(0);
}
else actionImageView=(ImageView)convertView;
actionImageView.setImageResource(actionsImagesResources[position]);
return actionImageView;
}
}
而這裏的佈局:
<GridView android:id="@+id/paint_actions_grid" android:layout_width="0dip"
android:layout_height="fill_parent" android:numColumns="2"
android:layout_weight="0.15" android:drawSelectorOnTop="true"/> <!-- android:background="@color/ui_background_color"/> -->
<!-- android:listSelector="@drawable/actions_list_selector"/> -->
感謝您的幫助。
下面是GridView如何看起來像現在(現在,所有項目都有相同的圖像)的圖像捕獲。我想要在選定的圖像周圍繪製某種顏色的框架,但我會看到一個橙色的矩形,在一秒鐘後消失,如我所說。
你可以發佈它現在看起來像什麼圖像,也許你正試圖讓它看起來像? – FoamyGuy