您好我已创建CustomListView
复选框。当我点击第一个项目时,它也会自动启用第三个项目。怎么解决?
holder.orderCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(((CheckBox)v).isChecked()) {
checkboxstate[position]=true;
if(observationDetailsList.get(position).LaboratoryUid.toString().equalsIgnoreCase(GlobalVariables.UUIDEmpty.toString()))
{
displayWarning();
}
patientOrderList.add(orderDetailsList.get(position));
patientObservationList.add(observationDetailsList.get(position));
} else {
checkboxstate[position]=false;
patientOrderList.remove(orderDetailsList.get(position));
patientObservationList.remove(observationDetailsList.get(position));
}
}
});
答案 0 :(得分:0)
以下是处理此
的完整适配器类我正在使用toogle按钮,并且您可以使用相同的复选框来维护复选框的状态
public class SettingsListAdapter extends BaseAdapter implements
{
private LayoutInflater mInflater;
private DealsSTRUC[] setings_Adapt_Catagories;
Context mContext;
String isNotificationEnnabled;
public SettingsListAdapter( Context context, DealsSTRUC[] catagories ,String isEnnabled)
{
mContext = context;
setings_Adapt_Catagories = catagories;
mInflater = LayoutInflater.from(context);
isNotificationEnnabled=isEnnabled;
}
@Override
public int getCount()
{
return setings_Adapt_Catagories.length;
}
@Override
public Object getItem(int arg0)
{
return null;
}
@Override
public long getItemId(int position)
{
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
SettingsAdptorViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.adapter_settingslist, null);
holder = new SettingsAdptorViewHolder();
holder.settings_catagory = (TextView) convertView.findViewById(R.id.settings_lable_text);
holder.settings_list_checkbox = (ToggleButton) convertView.findViewById(R.id.settings_checkbox);
holder.settings_list_checkbox.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
ToggleButton cb = (ToggleButton) v;
if (cb.isChecked() == true)
{
setings_Adapt_Catagories[position].setStatus("true");
}
else
{
setings_Adapt_Catagories[position].setStatus("false");
}
}
});
convertView.setTag(holder);
}
else
{
holder = (SettingsAdptorViewHolder) convertView.getTag();
}
if(setings_Adapt_Catagories[position].getStatus().equals("true")&&isNotificationEnnabled.equals("on"))
{
holder.settings_list_checkbox.setChecked(true);
}
else if(setings_Adapt_Catagories[position].getStatus().equals("false"))
{
holder.settings_list_checkbox.setChecked(false);
}
holder.settings_catagory.setText(setings_Adapt_Catagories[position].getDealName());
return convertView;
}
class SettingsAdptorViewHolder
{
TextView settings_catagory;
ToggleButton settings_list_checkbox;
}
}