您好我是Android开发人员.Herewith我提到了我的代码。我在自定义列表视图中添加了复选框我正在使用Base Adapter。虽然选中了复选框,但该项选择非常好但在选中后滚动复选框自动取消选中。如何解决这个问题。请给我解决方案。
class LabOrderListAdapter extends BaseAdapter {
LayoutInflater mInflater;
ViewHolder holder;
Boolean checkboxstate[];
Context context;
// DecimalFormat df = new DecimalFormat("#.##");
public LabOrderListAdapter(Context context) {
mInflater = LayoutInflater.from(context);
checkboxstate=new Boolean[observationDetailsList.size()];
for(int i=0;i<checkboxstate.length;i++)
checkboxstate[i]=false;
this.context = context;
}
public int getCount() {
if (observationDetailsList != null) {
Log.i(this.toString(), "observationDetailsList"+observationDetailsList.size());
return observationDetailsList.size();
}
return 0;
}
public Object getItem(int arg0) {
return arg0;
}
public long getItemId(int arg0) {
return arg0;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.lab_order_listitem, null);
}
if (v != null) {
holder = new ViewHolder();
holder.txt_Order_code = (TextView) v
.findViewById(R.id.orderingcode);
holder.txt_ProcedureCode = (TextView) v
.findViewById(R.id.procedurecode);
holder.txt_Laboratory = (TextView) v
.findViewById(R.id.Laboratory);
holder.billtypeButton = (AprimaButton) v.findViewById(R.id.billtype);
holder.txt_Order_Description = (TextView) v
.findViewById(R.id.description);
holder.txt_Date = (TextView) v
.findViewById(R.id.collectionDate);
holder.orderCheckBox = (CheckBox) v
.findViewById(R.id.checkboxorder);
holder.txt_TrackingNumber = (TextView) v
.findViewById(R.id.accession);
if(checkboxstate[position]==null){
checkboxstate[position]=false;
}
if(observationDetailsList.get(position).GenerateLabOrder.equalsIgnoreCase("Flase"))
{
holder.orderCheckBox.setChecked(checkboxstate[position]);
}
if (observationDetailsList.get(position).GenerateLabOrder
.equalsIgnoreCase("False"))
{
holder.orderCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(((CheckBox)v).isChecked()){
if (checkboxstate[position] = true)
{
patientOrderList.add(orderDetailsList.get(position));
patientObservationList.add(observationDetailsList.get(position));
}
else{
if (checkboxstate[position] = false)
{
checkboxstate[position]=false;
patientOrderList.remove(orderDetailsList.get(position));
patientObservationList.remove(observationDetailsList.get(position));
}
}
}
}
});
}
v.setTag(holder);
}
return v;
}
}
答案 0 :(得分:0)
您需要定义一个Model来存储ListItem的已检查信息。 在getView()方法中,您需要从Model类中获取每个项的值。
smiler示例在此Blog
中给出