在我的应用程序中,我有 ListView 和我的 ListView 的适配器。我的项目 ListView 有两个元素 Text 和 Image。现在我想分离文字并点击图片。
public class MyAdapter extends ArrayAdapter<String> {
private Activity context;
private ArrayList<String> categories;
public static boolean remove = true;
public MyAdapter(Activity context, ArrayList<String> categories) {
super(context, R.layout.my_list_element, categories);
this.context = context;
this.categories = categories;
}
static class ViewHolder {
public TextView tvLanguage;
public ImageView remove;
}
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.my_list_element, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.tvLanguage = (TextView) rowView.findViewById(R.id.tvLanguage);
viewHolder.remove = (ImageView) rowView.findViewById(R.id.remove);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.tvLanguage.setText(categories.get(position));
if(remove)
holder.remove.setVisibility(View.GONE);
else
holder.remove.setVisibility(View.VISIBLE);
return rowView;
}
我应该如何分离文本和图像并成功在两个元素上使用 setOnClickListener ?