【发布时间】:2016-03-15 09:24:29
【问题描述】:
我想要一个没有颜色的心,当我点击它时,它的颜色变成红色并在退出应用时保存。
StructAnatomy 类:
public class StructAnatomy {
public String title;
//public ImageView heart_empty;
//public boolean done;
}
AdapterAnatomy 类:
heart_impty 是没有颜色的图像,而 heart_fill 是有颜色的。
public class AdapterAnatomy extends ArrayAdapter<StructAnatomy> {
public AdapterAnatomy(ArrayList<StructAnatomy> array) {
super(G.context, R.layout.adapter_anatomy, array);
}
public static class ViewHolder {
public ViewGroup layoutRoot;
public TextView txtTitle;
//public ImageView heart_empty;
public ViewHolder(View view) {
layoutRoot = (ViewGroup) view.findViewById(R.id.layoutRoot);
txtTitle = (TextView) view.findViewById(R.id.txtTitle);
//heart_empty.setImageResource(R.drawable.heart_fill);
}
public void fill(ArrayAdapter<StructAnatomy> adapter, StructAnatomy item, final int position) {
txtTitle.setText(item.title);
//heart_empty.setEnabled(item.done);
layoutRoot.setOnClickListener(new OnClickListener() {
//******************************************************************************************
@Override
public void onClick(View arg0) {
Intent intent = new Intent(G.currentActivity, Anatomy1_2.class);
intent.putExtra("POSITION", position);
G.currentActivity.startActivity(intent);
}
});
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
StructAnatomy item = getItem(position);
if (convertView == null) {
convertView = G.inflater.inflate(R.layout.adapter_anatomy, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.fill(this, item, position);
return convertView;
}
}
【问题讨论】:
-
你能分享你所做的代码吗?一种方法可以放在用于每个行视图的 row.xml
-
你有没有尝试过这样做?
-
是的 // 我解释我的尝试
-
你是否使用任何api来获取喜欢或不喜欢的数据?
-
基本上,您需要一个自定义 CheckBox 或 RadioButton。谷歌。
标签: android xml android-layout listview android-studio