我有一个带有editext和复选框的自定义列表视图。数据从数据库填充到列表中,我需要检查哪个复选框被选中并将该选中复选框的填充文本视图的ID存储到数据库中。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final TestListPojo objTest = testList.get(position);
final String testitem = objTest.getTestname();
barcode = objTest.getBarcode();
if (convertView == null) {
LayoutInflater layoutInflater = LayoutInflater.from(myContext);
convertView = layoutInflater.inflate(R.layout.testlist_inflator,
null);
ViewHolder holder = new ViewHolder();
holder.test = (TextView) convertView.findViewById(R.id.test);
holder.ch_check = (CheckBox) convertView
.findViewById(R.id.ch_check);
holder.et_barcode = (EditText) convertView
.findViewById(R.id.et_testbarcode);
convertView.setTag(holder);
if (!barcode.equalsIgnoreCase("") && !(barcode == null)) {
holder.et_barcode.setText(barcode);
/*for (int i = 0; i < barcode.length(); i++) {
StringBuilder sb = new StringBuilder(barcode);
// StringBuffer sb = new StringBuffer(barcode);
String save=sb.append(",").append(i).toString();
}
*/
}
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
final TextView test = (TextView) convertView
.findViewById(R.id.textView1);
holder.test.setText(testitem);
holder.test.setClickable(true);
holder.test.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
test.getText().toString();
System.out.println(test.getText().toString());
}
});
holder.ch_check
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
CheckBox ch = (CheckBox) buttonView;
if (ch.isChecked()) {
/*ch.get
System.out.println(ch.getImeActionLabel().toString());
*/
}
}
});
return convertView;
}
static class ViewHolder {
TextView test;
CheckBox ch_check;
EditText et_barcode;
}
}
| testname1 barcode1 checkbox |
| testname2 barcode1 checkbox |
| ' ' ' |
| ' ' ' |
| |
| |
测试名称和条形码是从数据库中填充的,我需要检查是否选择了哪个测试。并更新在 db 中选择了这个测试。