Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck box in listview not working properly
    primarykey
    data
    text
    <p>I am implementing the checkbox with listview for every Iten of listview.The Problem i am getting is when I am clicking on any single check box and when i scroll then some other checkboxes which are not clicked also getting clicked randomly. i went through many link on SO but it did'nt solve my problem. </p> <pre><code>public class CustomListViewAdapter extends ArrayAdapter&lt;Client&gt; { ViewHolder holder = null; private LayoutInflater inflator = null; private ArrayList&lt;Client&gt; orderList = null; ArrayList&lt;View&gt; allViews; public CustomListViewAdapter(Context context, int resource, List&lt;Client&gt; objects) { super(context, resource, objects); orderList = (ArrayList&lt;Client&gt;) objects; inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); allViews = new ArrayList&lt;View&gt;(); } @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView == null) { convertView = inflator.inflate(R.layout.listview_add_order, null); holder = new ViewHolder(); convertView.setTag(holder); holder.txtViewName = (TextView) convertView.findViewById(R.id.txtViewAddOrder); holder.spinnerAddorder = (Spinner) convertView.findViewById(R.id.spinnerAddOrder); holder.checkAddorder = (CheckBox) convertView.findViewById(R.id.checkAddOrder); holder.checkAddorder.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); holder.checkAddorder.setTag(holder); } allViews.add(position, holder.spinnerAddorder); holder.checkAddorder.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { CheckBox cchk = (CheckBox)view; ViewHolder checkPosition = (ViewHolder) view.getTag(); if(cchk.isChecked()) { checkPosition.spinnerAddorder.setVisibility(View.VISIBLE); } else { checkPosition.spinnerAddorder.setVisibility(View.INVISIBLE); } } }); List&lt;String&gt; list = new ArrayList&lt;String&gt;(); list.add("Select Quantity"); list.add("1"); list.add("2"); list.add("3"); ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this.getContext(),R.layout.spinner_add_order_style, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); holder.spinnerAddorder.setAdapter(dataAdapter); if(holder.checkAddorder.isChecked()) { ViewHolder checkPosition = (ViewHolder) holder.checkAddorder.getTag(); checkPosition.spinnerAddorder.setVisibility(View.VISIBLE); } else { ViewHolder checkPosition = (ViewHolder) holder.checkAddorder.getTag(); checkPosition.spinnerAddorder.setVisibility(View.INVISIBLE); } Client order = orderList.get(position); holder.txtViewName.setText(order.getFirstName()); return convertView; } private static class ViewHolder { public TextView txtViewName = null; public Spinner spinnerAddorder = null; public CheckBox checkAddorder = null; } } </code></pre> <p>my xml file is</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="5dp" android:paddingRight="5dp" android:weightSum="2" &gt; &lt;TextView android:id="@+id/txtViewAddOrder" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1.2" android:text="TextView" android:textSize="25sp" /&gt; &lt;Spinner android:id="@+id/spinnerAddOrder" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight=".8" android:background="@drawable/dropdown" /&gt; &lt;CheckBox android:id="@+id/checkAddOrder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" /&gt; &lt;/LinearLayout&gt; </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.
 

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