带有删除按钮的微调器会禁用项目

时间:2012-08-06 04:06:34

标签: android spinner android-spinner

我的活动中有一个微调器。当用户点击下拉按钮时,我需要显示文本和删除按钮。

所以我写了自定义数组适配器,它正确渲染。但我只能点击删除按钮,它会在Click事件上删除按钮。这是预期的,但当我点击文本时,我不能再选择该项目了。除删除按钮单击外,所有行都被禁用。

1 个答案:

答案 0 :(得分: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}