Reputation: 3159
I have an spinner in my activity. I need to show text and delete button when user click the drop down button.
So I wrote Custom Array Adapter and it is render correctly. But I can only click the delete button and it go to delete button on Click event. It is as expect but I cant choose the item anymore when I click the text. All row are disabled except delete button click.
Upvotes: 0
Views: 670
Reputation: 3159
//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}
Upvotes: 1