我有一个Listactivity,其中包含一个带有TextView和Button(标记为delete)的适配器。现在我想删除相应的Button点击项。 请检查代码并提供建议???
public class MySimpleArrayAdapter extends ArrayAdapter<String> implements OnClickListener {
private final Activity context;
private final String[] names;
private Button deleteButton= null;
public MySimpleArrayAdapter(Activity context, String[] names) {
super (context, R.layout.imagelistlayout, names);
this.context = context;
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.imagelistlayout, null, true);
deleteButton= (Button)rowView.findViewById(R.id.delete_bn);
deleteButton.setTag(position);
TextView textView = (TextView) rowView.findViewById(R.id.label);
textView.setText(names[position]);
deleteButton.setOnClickListener(this);
return rowView;
}
@Override
public void onClick(View convertView) {
System.out.println(deleteButton.getTag());
}
}`
我想知道如何删除被点击按钮对应的项目。