2012-08-06 47 views
0

我有一個微調在我的活動。當用戶點擊下拉按鈕時,我需要顯示文本和刪除按鈕。微調刪除按鈕使項目禁用

所以我寫了自定義數組適配器,並且它正確渲染。但我只能點擊刪除按鈕,然後點擊Click事件中的刪除按鈕。這是預期的,但我不能選擇該項目了,當我點擊文字。除刪除按鈕點擊之外,所有行均被禁用。

+3

請把你正在使用的代碼。這可能會使事情變得容易理解。 – 2012-08-06 04:23:12

回答

1
//CUSTOM SPINNER ADAPTER 
public class CardListAdapter extends ArrayAdapter<Card> { 
private Context appContext = null; 
private ArrayList<Card> items = null; 

public CardListAdapter(Context context, int textViewResourceId, 
     ArrayList<Card> items) { 
    super(context, textViewResourceId, items); 
    this.appContext = context; 
    this.items = items; 
} 

@Override 
public View getDropDownView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    return getCustomView(position, convertView, parent); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    View v = convertView; 
    if (v == null) { 
     LayoutInflater vi = (LayoutInflater) appContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = vi.inflate(R.layout.card_simple_list, null); 
    } 

    final Card o = items.get(position); 
    if (o != null) { 

     TextView name = (TextView) v.findViewById(R.id.card_Name); 

     if (name != null) { 
      name.setText(o.getName()); 
     } 
    } 
    return v; 

} 

public View getCustomView(int position, View convertView, ViewGroup parent) { 
    View v = convertView; 
    if (v == null) { 
     LayoutInflater vi = (LayoutInflater) appContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = vi.inflate(R.layout.card_list, null); 
    } 

    final Card o = items.get(position); 
    if (o != null) { 

     TextView name = (TextView) v.findViewById(R.id.card_Name); 

     ImageButton btnDelete = (ImageButton) v 
       .findViewById(R.id.card_Delete); 

     btnDelete.setOnClickListener(new OnClickListener() { 

      public void onClick(View view) { 
       items.remove(o); 
       notifyDataSetChanged(); 
      } 
     }); 

     if (name != null) { 
      name.setText(o.getName()); 
     } 
    } 
    return v; 
} 

} // end custom adapter} 
+0

得到了答案。我應該使用圖像視圖而不是ImageButton。 – 2012-08-08 16:09:28

+1

請將問題標記爲已回答 – 2012-08-09 12:38:47