在我的应用程序中,我在列表视图中显示一些项目,每行有一个名称和一个刻度图像。勾选图像仅在选择(选中)项目时显示,选择工作正常,但问题是当选择新项目时,之前选择的项目的勾选不会变为不可见。如何解决这个问题?任何帮助将不胜感激 这是我的代码
适配器
if("file/directory not found".equals(exception.value)) ...
FragmentPart(项目点击监听器)
public class ListAdapter extends BaseAdapter {
private LayoutInflater inflater;
Context context;
private ArrayList<String> responseList;
private LinearLayout parent_choice_list_container;
private TextView item_name;
private ImageView iv_choice_list_item_selected;
public ListAdapter (Context context, ArrayList<String> responseList) {
this.context = context;
this.responseList = responseList;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setSelectedIndex(int ind) {
selectedIndex = ind;
notifyDataSetChanged();
}
@Override
public int getCount() {
return responseList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.menu_list_item, null);
}
parent_choice_list_container = (LinearLayout) view.findViewById(R.id.parent_choice_list_container);
item_name = (TextView) view.findViewById(R.id.item_name);
iv_choice_list_item_selected = (ImageView) view.findViewById(R.id.iv_choice_list_item_selected);
iv_logo = (ImageView) view.findViewById(R.id.iv_blog_category_logo);
if (responseList.get(position).isSelected()) {
iv_choice_list_item_selected.setVisibility(View.VISIBLE);
} else {
iv_choice_list_item_selected.setVisibility(View.GONE);
} list_item_name.setText(responseList.get(position).getName());
return view;
}
}
答案 0 :(得分:0)
听起来你正在使用CheckBox
。
您是否尝试过有条不紊地更新View
的可见度,具体取决于项isChecked
(和不 isSelected
)?
答案 1 :(得分:0)
你应该为每个图像设置标记以跟踪其状态(0 =未选中/不可见,1 =选择/可见),例如:
if (responseList.get(position).isSelected()) {
iv_choice_list_item_selected.setTag(1);
}
你可以添加:
if (iv_choice_list_item_selected.getTag() == 1) {
iv_choice_list_item_selected.setVisibility(View.VISIBLE);
} else {
iv_choice_list_item_selected.setVisibility(View.GONE);
}