显示上一个选择的列表视图 [ANDROID]



在我的应用程序中,我在列表视图中显示一些项目,每行都有一个名称和一个勾号图像。刻度图像仅在选择(选中(项目时显示,选择工作正常,但问题是当选择新项目时,先前选择项目的刻度不可见。如何解决这个问题?任何帮助将不胜感激 这是我的代码

适配器

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;
}
}

片段部分(项目单击侦听器(

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
response.get(position).setSelected(true);
ListAdapter.notifyDataSetChanged(); 
}

听起来您正在使用CheckBox

您是否尝试过根据项目是否isChecked(而不是isSelected(有条件地更新View的可见性?

您应该为每个图像设置标签以跟踪其状态(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);
}            

最新更新