Note that there are some explanatory texts on larger screens.

plurals
  1. POAlertdialg with custom adapter containg checkbox and its listener
    primarykey
    data
    text
    <p>I am using <code>custom adpater in AlertDialog</code>. In that adapter, i am using <code>TextView and CheckBox</code>.. Now I want to handle CheckBox's <code>setOnCheckedChangeListener</code> for checking checked or unchecked CheckBox.. And according to status of CheckBox, I want to implement some code. But this listener is fired more than one time.. So how can I handle it? Suggest me if anyone has an idea.</p> <p>And exactly my problem is when i checked on checkbox, i want to increment some value and when i unchecked, i want to decrement some value.but i am not getting exact sum value and if i scroll then this sum value is changed.. so what i have to do?</p> <p>Following is my Custom Adaper :</p> <pre><code>private class Updateinfo_ServiceAdapter extends BaseAdapter { @Override public int getCount() { // TODO Auto-generated method stub return _options_services.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { Viewholder holder; LayoutInflater inflater=getLayoutInflater(); if(convertView==null) { convertView=inflater.inflate(R.layout.row_updateinfo_service, null); holder=new Viewholder(); holder.txtname=(TextView)convertView.findViewById(R.id.serviceName); holder.chkSelected=(CheckBox)convertView.findViewById(R.id.chk); convertView.setTag(holder); } else { holder=(Viewholder)convertView.getTag(); } holder.txtname.setText(_options_services[position]); holder.chkSelected.setChecked(_selections_services[position]); holder.chkSelected.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { allowServicesSum = allowServicesSum + Integer.parseInt((String) services[position] .getSystemServiceID()); System.out.println("AllowService sum is "+allowServicesSum); } else { allowServicesSum = allowServicesSum - Integer.parseInt((String) services[position] .getSystemServiceID()); System.out.println("AllowService sum is "+allowServicesSum); } } }); if(_selections_services[position]) { holder.chkSelected.setEnabled(false); } else { holder.chkSelected.setEnabled(true); } return convertView; } private class Viewholder { TextView txtname; CheckBox chkSelected; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload