0
我已經使用baseAdepter在列表中顯示三個視圖。 前兩個是textView,最後一個是checkBox View。 但是,當我去檢查的複選框和滾動列表,在項目的某些特定號碼後,其他的複選框是自動unaseptedlly檢查..android問題帶有baseAdapter的複選框
我沒有辦法,爲什麼這種事情發生是。
是誰德誰知道它的解決方案..
這裏是我的baseadepter代碼..
private static class AdepterGetUnit extends BaseAdapter{
private LayoutInflater mInflater;
public AdepterGetUnit (Context context){
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
positionList = sharedPreferences.getInt(UnitScreen.POSITION, 0);
if(positionList==0){currentListLenght=ArrayHolder.dbSpeed.size();}
else if(positionList==1){currentListLenght=ArrayHolder.dbAngle.size();}
else if(positionList==2){currentListLenght=listTemperature.length;}
else if(positionList==3){currentListLenght=ArrayHolder.dbLenght.size();}
else if(positionList==4){currentListLenght=ArrayHolder.dbWeightMass.size();}
else if(positionList==5){currentListLenght=ArrayHolder.dbPressure.size();}
else if(positionList==6){currentListLenght=ArrayHolder.dbPower.size();}
else if(positionList==7){currentListLenght=ArrayHolder.dbCurrency.size();}
else if(positionList==8){currentListLenght=ArrayHolder.dbDataSize.size();}
else if(positionList==9){currentListLenght=ArrayHolder.dbVolume.size();}
else if(positionList==10){currentListLenght=ArrayHolder.dbTime.size();}
else if(positionList==11){currentListLenght=ArrayHolder.dbArea.size();}
else if(positionList==12){currentListLenght=ArrayHolder.dbCoocking.size();}
return currentListLenght;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView==null){
convertView = mInflater.inflate(R.layout.row_edit_unit, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.txt_show_units);
holder.textTotle = (TextView) convertView.findViewById(R.id.txt_unit);
holder.checkBox = (CheckBox) convertView.findViewById(R.id.check_box);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
// positionList = sharedPreferences.getInt(UnitScreen.POSITION, 0);
switch (positionList) {
case 0:
holder.text.setText(ArrayHolder.dbSpeed.get(position));
holder.textTotle.setText(ArrayHolder.dbSpeedUnit.get(position));
txtUnitTitleName.setText("Speed");
break;
case 1:
holder.text.setText(ArrayHolder.dbAngle.get(position));
holder.textTotle.setText(ArrayHolder.dbAngleUnit.get(position));
txtUnitTitleName.setText("Angle");
break;
case 2:
holder.text.setText(ArrayHolder.dbTemperature.get(position));
holder.textTotle.setText(ArrayHolder.dbTemperatureUnit.get(position));
txtUnitTitleName.setText("Temperature");
break;
case 3:
holder.text.setText(ArrayHolder.dbLenght.get(position));
holder.textTotle.setText(ArrayHolder.dbLenghtUnit.get(position));
txtUnitTitleName.setText("Lenght");
break;
case 4:
holder.text.setText(ArrayHolder.dbWeightMass.get(position));
holder.textTotle.setText(ArrayHolder.dbWeightMassUnit.get(position));
txtUnitTitleName.setText("Weight/Mass");
break;
case 5:
holder.text.setText(ArrayHolder.dbPressure.get(position));
holder.textTotle.setText(ArrayHolder.dbPressureUnit.get(position));
txtUnitTitleName.setText("Pressure");
break;
case 6:
holder.text.setText(ArrayHolder.dbPower.get(position));
holder.textTotle.setText(ArrayHolder.dbPowerUnit.get(position));
txtUnitTitleName.setText("Power");
break;
case 7:
holder.text.setText(ArrayHolder.dbCurrency.get(position));
holder.textTotle.setText(ArrayHolder.dbCurrencyUnit.get(position));
if(!holder.checkBox.isChecked())
holder.checkBox.setChecked(false);
else
holder.checkBox.setChecked(true);
txtUnitTitleName.setText("Currency");
break;
case 8:
holder.text.setText(ArrayHolder.dbDataSize.get(position));
holder.textTotle.setText(ArrayHolder.dbDataSizeUnit.get(position));
txtUnitTitleName.setText("DataSize");
break;
case 9:
holder.text.setText(ArrayHolder.dbVolume.get(position));
holder.textTotle.setText(ArrayHolder.dbVolumeUnit.get(position));
txtUnitTitleName.setText("Volume");
break;
case 10:
holder.text.setText(ArrayHolder.dbTime.get(position));
holder.textTotle.setText(ArrayHolder.dbTimeUnit.get(position));
txtUnitTitleName.setText("Time");
break;
case 11:
holder.text.setText(ArrayHolder.dbArea.get(position));
holder.textTotle.setText(ArrayHolder.dbAreaUnit.get(position));
txtUnitTitleName.setText("Area");
break;
case 12:
holder.text.setText(ArrayHolder.dbCoocking.get(position));
txtUnitTitleName.setText("Coocking");
break;
default:
break;
}
return convertView;
}
static class ViewHolder {
TextView text ,textTotle;
ImageView icon;
CheckBox checkBox;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position-1;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position-1;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
}