gpt4 book ai didi

android - ListView 数据在滚动时被清除

转载 作者:行者123 更新时间:2023-11-29 20:50:33 26 4
gpt4 key购买 nike

<分区>

我正在开发一个显示 listViewcheckBoxes 的应用程序。当我滚动 listView 时,CheckBoxes 的值被清除。

下面是我的代码

适配器类:

public class Conference_listViewAdapter extends BaseAdapter {
Activity context;
LayoutInflater inflater;
public static List<Model> data = null;
ArrayList<String> id_list = new ArrayList<String>();
ViewHolder holder;
int pos;

public Conference_listViewAdapter(Activity context,List<Model> list, ArrayList<String> id_list) {
data = list;
this.id_list = id_list;
this.context = context;
}


@Override
public int getCount() {
return data.size();
}


@Override
public Object getItem(int position) {
return data.get(position).getName();
}

@Override
public long getItemId(int position) {
return Long.valueOf(id_list.get(position));
}

public View getView(final int position, View convertView, ViewGroup parent) {

View view = null;

if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.people_list_item1, null);
holder = new ViewHolder();
holder.title = (TextView) view.findViewById(R.id.tv_name);
holder.image = (ImageView) view.findViewById(R.id.avtaar);
holder.favorite = (CheckBox) view.findViewById(R.id.fav);
holder.favorite.setTag(position);
view.setTag(holder);

holder.favorite.setTag(data.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).favorite.setTag(data.get(position));
}


holder.favorite.setOnCheckedChangeListener(new OnCheckedChangeListener() {

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Model element = (Model) holder.favorite.getTag();
element.setSelected(buttonView.isChecked());
//notifyDataSetChanged();
}
});


ViewHolder holder = (ViewHolder) view.getTag();

holder.favorite.setChecked(data.get(position).isSelected());
holder.title.setText(data.get(position).getName());



try {
holder.image.setImageBitmap(openPhoto(Long.valueOf(id_list.get(position))));
} catch (Exception e) {
e.printStackTrace();
}

return view;
}

class ViewHolder {
TextView title;
TextView model;
ImageView image;
CheckBox favorite;
}


}

数据模型类

public class Model {

private String name;
private boolean selected;

public Model(String name) {
this.name = name;
selected = false;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isSelected() {
return selected;
}

public void setSelected(boolean selected) {
this.selected = selected;
}

}

不知道我哪里做错了。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com