В моем приложении я добавил checkbox
с ListView
, и я также дал ограничение для checkbox
, пользователь не может выбрать более 5 checkbox
, но проблема заключается в прокрутке моего выбранного checkbox
неконтролируемого следующий мой код фрагмента, может ли кто-нибудь помочь мне с этим
public class CustomAdapter extends BaseAdapter {
private LayoutInflater inflater = null;
Context context;
String rup = "\u20B9";
private ArrayList<ModelPooja> listData;
boolean checked[];
public CustomAdapterPooja(Context mainActivity, ArrayList<ModelPooja> listData) {
// TODO Auto-generated constructor stub
context = mainActivity;
this.listData = listData;
inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
checked = new boolean[listData.size()];
for (int i = 0; i < checked.length; i++) {
checked[i] = listData.get(i).isselected;
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return listData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_item_poojaselection, null);
holder.tv = (TextView) convertView.findViewById(R.id.list_item_poojaname);
holder.serviceprice = (TextView) convertView.findViewById(R.id.list_item_poojaprice);
holder.dayss = (TextView) convertView.findViewById(R.id.list_item_poojadays);
holder.txtseledates = (TextView) convertView.findViewById(R.id.selecteddatess);
holder.checks = (CheckBox) convertView.findViewById(R.id.list_item_poojacheck);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.checks.setOnCheckedChangeListener(null);
holder.checks.setFocusable(false);
holder.checks.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton cb, boolean b) {
if (checkMaxLimit()) {
if (listData.get(position).isselected && b) {
holder.checks.setChecked(false);
listData.get(position).isselected = false;
} else {
holder.checks.setChecked(false);
listData.get(position).isselected = false;
Toast.makeText(context, "Max limit reached", Toast.LENGTH_SHORT).show();
}
} else {
if (b) {
listData.get(position).isselected = true;
} else {
listData.get(position).isselected = false;
}
}
}
});
if (listData.get(position).isselected()) {
holder.checks.setChecked(true);
} else {
holder.checks.setChecked(false);
}
holder.tv.setText(listData.get(position).getPOOJA_LISTING_NAME());
holder.dayss.setText(listData.get(position).getPOOJA_LISTING_DAYS());
holder.serviceprice.setText(rup + listData.get(position).getPOOJA_LISTING_AMOUNT());
return convertView;
}
public boolean checkMaxLimit() {
int countermax = 0;
for (int i = 0; i < checked.length; i++) {
checked[i] = false;
checked[i] = listData.get(i).isselected();
if (listData.get(i).isselected()) {
countermax++;
}
}
return countermax >= 5 ? true : false;
}
public class ViewHolder {
TextView tv;
TextView serviceprice;
public CheckBox checks;
public TextView dayss;
public TextView txtseledates;
}
}