【发布时间】:2017-06-09 05:49:02
【问题描述】:
我正在尝试在列表视图中编辑内容,但是当单击以更新某些项目时,其他位置也会更新。这些数据保存在 SQLite 数据库中。请看下面我的适配器
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
txtId = (TextView) v.findViewById(R.id.txtId);
txtValue = (TextView) v.findViewById(R.id.txtValue);
ckb = (CheckBox) v.findViewById(R.id.ckbEnable);
btnUpdate = (Button) v.findViewById(R.id.btnUpdate);
final String id = list.get(position).get("id").toString();
final String value= list.get(position).get("value").toString();
boolean bval = list.get(position).get("enbl").toString().equals("true") ? true : false;
txtId.setText(id);
txtValue.setText(value);
ckb.setChecked(bval);
btnUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
control = new DataControl(context);
cal = new DataCal();
cal.setId(id);
cal.setValue(txtValue.getText().toString());
cal.setEnable(String.valueOf(ckb.isChecked()));
int ctrl = control.editCal(cal);
if (ctrl > 0)
MessageBox("Success on updating");
else
MessageBox("Error while updating!");
}
});
return v;
【问题讨论】:
-
你能发布整个适配器吗?
-
希望对您有所帮助....stackoverflow.com/questions/44407057/…
标签: android