listView
안에 checkbox
을 클릭하면 textView
이 Paint.STRIKE_THRU_TEXT_FLAG)
으로 청구되는 문제가 있습니다. 사용자가 checkbox
을 클릭하면 경고 라인이 textView
에 표시됩니다.textView에 Paint.STRIKE_THRU_TEXT_FLAG를 설정하십시오
public void bindView(View row, Context context, Cursor c) {
// TODO Auto-generated method stub
listName = (TextView) row.findViewById(R.id.produtName);
listCheck = (CheckBox) row.findViewById(R.id.check);
Item tag = (Item) listCheck.getTag();
String pos = helper.getProductId(c);
Log.i(CN, "getView: no tag on " + pos);
tag = new Item();
tag.id = Integer.parseInt(pos);
listCheck.setTag(tag);
listCheck.setChecked(false);
String status = helper.getProductStatusT(c);
if (Integer.parseInt(status) == 0) {
listCheck.setChecked(true);
listName.setPaintFlags(listName.getPaintFlags()
| Paint.STRIKE_THRU_TEXT_FLAG);
} else {
listCheck.setChecked(false);
listName.setPaintFlags(listName.getPaintFlags()
& (~Paint.STRIKE_THRU_TEXT_FLAG));
}
public View getView(int position, View convertView, ViewGroup parent) {
View tmpView = super.getView(position, convertView, parent);
Log.i(CN, "getView:" + position);
final CheckBox cBox = (CheckBox) tmpView.findViewById(R.id.check);
Item tag = (Item) cBox.getTag();
cBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Item tag = (Item) v.getTag();
if (tag == null)
Log.i(CN, "checkbox clicked no tag");
else
helper.updateStatus(tag.id);
Log.i(CN, "checkbox clicked tag=" + tag.id);
}
if (cBox.isChecked()) {
Log.i(CN, " Checked!");
// do some operations here
} else {
Log.i(CN, "NOT Checked!");
// do some operations here
helper.updateStatus2(tag.id);
}
}
});
return tmpView;
}
checkBox가 정상적으로 작동합니다. 그러나 문제는 사용자가 체크 박스를 클릭하면 스트라이크 라인이 표시되지 않는다는 것입니다.
public class CustomCursorAdapter extends CursorAdapter {
private LayoutInflater inflator;
private boolean[] arrCb;
public CustomCursorAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
arrCb = new boolean[c.getCount()];
//^this will hold the checkbox states
resetArrcb();
}
@Override
public View newView(Context context, Cursor c, ViewGroup parent) {
View v = inflator.inflate(R.layout.lv_row, parent, false);
// inflate the xml that the textView and checkbox is in
return v;
}
@Override
public void bindView(View row, Context context, final Cursor cursor) {
// you do everything else here. there's no need for getView when you use newView and bindView
final TextView listName = (TextView) row.findViewById(R.id.produtName);
final CheckBox listCheck = (CheckBox) row.findViewById(R.id.check);
if (arrCb[cursor.getPosition()]) {
listCheck.setChecked(true);
listName.setPaintFlags(listName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
listCheck.setChecked(false);
listName.setPaintFlags(listName.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
listCheck.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (listCheck.isChecked()) {
arrCb[cursor.getPosition()] = true;
} else {
arrCb[cursor.getPosition()] = false;
}
notifyDataSetChanged();
}
});
}
private void resetArrcb() {
// i'm using this to fill the collection but you could easily loop through your
// database to fill it with the correct values.
for (int i = 0; i < arrCb.length; i++) {
arrCb[i] = false;
}
}
}
을 그리고 난 잘 모르겠어요 : 사람은 내가 당신을 위해 노력하고 다음과 같은 경우에 나는 당신이 지금 시도 할 수있는 어떤 아이디어가있을 수 있습니다 생각
listName.setPaintFlags(listName.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG);
첫 번째로'newView '와 함께'bindView'를 사용하면 getView가 필요 없습니다. 'newView'를 사용하여 viewgroup xml을 부 풀린 다음,'bindView'에서 모든 코드를 수행하십시오. 그런데 왜 여기에 태그를 설정하고 가져 왔습니까? – mango
전에 시도해 보았지만 listview의 리사이클 메커니즘. 사용자가 체크 박스를 클릭 한 다음 productID에 따라 데이터베이스에 업데이트 할 때 productID를 가져오고 싶습니다. – johnk
사용자가 체크 박스를 클릭하면 productStatus가 데이터베이스로 업데이트됩니다. strike 라인을 표시하지 않았습니다 ... listName.setPaintFlags (listName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); public 내부에 넣어야합니다. View getView? – johnk