0

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

所以我写了自定义数组适配器,它渲染正确。但是我只能单击删除按钮,然后单击事件上的删除按钮。正如预期的那样,但是当我单击文本时我无法再选择该项目。除删除按钮单击外,所有行均被禁用。

4

1 回答 1

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}
于 2012-08-08T14:51:05.360 回答