title: Set CheckBox in ListView Android
body: <p>I have two listviews, rows have simple checkbox and TextView, when I click on checkbox in list1, I move the item to List2 and would like to show its checkbox as selected. Even though I am hardcoding checkbox.setSelected(true) in List2 adapter, but the checkbox doesn't seem to show the checkmark. Here is the code, any ideas?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="7dp"
  &gt;
  &lt;CheckBox
      android:id="@+id/checkbox1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      /&gt;
  &lt;TextView
      android:id="@+id/item_title"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:gravity="center_vertical"
      android:layout_alignParentTop="true"
      android:layout_alignParentBottom="true"
      android:textAppearance="?android:attr/textAppearanceMedium"
      android:textSize="14dp"
      android:textStyle="normal"
      android:layout_marginRight="25dp"
      android:layout_marginTop="5dp"
      android:layout_marginBottom="5dp"/&gt;
   &lt;/LinearLayout&gt;
  
     public class AlphabetListDemo extends Activity {
  
  //String of alphabets //
  List&lt;ListItem&gt; alphabets = new ArrayList&lt;ListItem&gt;();
  List&lt;ListItem&gt; prods = new ArrayList&lt;ListItem&gt;();
  
  ListView L1, L2;
  myAdapter myadp;
  myAdapter2 myadp2;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_alphabet_list_demo);
  
      L1 = (ListView)findViewById(R.id.list1);
      L2 = (ListView)findViewById(R.id.list2);
  
      myadp = new myAdapter(this,alphabets);
      myadp2 = new myAdapter2(this,prods);
      L1.setAdapter(myadp);
      L2.setAdapter(myadp2);
  
      L1.setOnItemClickListener(new AdapterView.OnItemClickListener(){
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,long arg3) {
              //add to Other List &amp; update
              prods.add(alphabets.get(arg2));
              L2.setAdapter(myadp2);
  
              //remove from current List &amp; update
              alphabets.remove(arg2);
              L1.setAdapter(myadp);
          }
      });
  
      L2.setOnItemClickListener(new AdapterView.OnItemClickListener(){
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,long arg3) {
              //add to Other List &amp; update
              alphabets.add(prods.get(arg2));
              L1.setAdapter(myadp);
  
              //remove from current List &amp; update
              prods.remove(arg2);
              L2.setAdapter(myadp2);
          }
      });
  
      final EditText textField = (EditText) findViewById(R.id.editText);
      Button addBtn = (Button) findViewById(R.id.addBtn);
      addBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              if(textField.getText().length()&gt;0){
                  alphabets.add(new ListItem(textField.getText().toString(),false));
                  L1.setAdapter(myadp);
              }
          }
      });
  
  }
  
  
  class myAdapter extends ArrayAdapter&lt;ListItem&gt;
  {
      TextView label;
      CheckBox checkBox;
      View row;
      public myAdapter(Context context,List&lt;ListItem&gt;list)
      {
          super(context, android.R.layout.simple_list_item_1, list);
      }
  
      public View getView(final int position, View convertView, ViewGroup parent)
      {
          try{
              LayoutInflater inflater=getLayoutInflater();
              row = inflater.inflate(R.layout.simple_list_item_1, parent, false);
              label = (TextView)row.findViewById(R.id.item_title);
              checkBox= (CheckBox)row.findViewById(R.id.checkbox1);
              label.setText(alphabets.get(position).description);
              label.setTextColor(Color.BLACK);
              checkBox.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      prods.add(alphabets.get(position));
                      L2.setAdapter(myadp2);
  
                      //remove from current List &amp; update
                      alphabets.remove(position);
                      L1.setAdapter(myadp);
                  }
              });
  
          }catch(Exception e){
  
          }
          return row;
      }
  }
  // adapter for second list.....
  class myAdapter2 extends ArrayAdapter&lt;ListItem&gt;
  {
      TextView label;
      CheckBox checkBox;
      View row;
      public myAdapter2(Context context,List&lt;ListItem&gt;list)
      {
          super(context, android.R.layout.simple_list_item_1, list);
      }
  
      public View getView(final int position, View convertView, ViewGroup parent)
      {
          try{
              LayoutInflater inflater=getLayoutInflater();
              row = inflater.inflate(R.layout.simple_list_item_1, parent, false);
              label = (TextView)row.findViewById(R.id.item_title);
              checkBox= (CheckBox)row.findViewById(R.id.checkbox1);
              label.setText(prods.get(position).description);
              label.setTextColor(Color.BLUE);
              checkBox.setSelected(true);
  
              checkBox.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      //add to Other List &amp; update
                      alphabets.add(prods.get(position));
                      L1.setAdapter(myadp);
  
                      //remove from current List &amp; update
                      prods.remove(position);
                      L2.setAdapter(myadp2);
                  }
              });
          }catch(Exception e){
  
          }
          return row;
      }
  }
  
  class ListItem{
      public boolean isSelected;
      public String description;
  
      ListItem(String description, boolean isSelected){
          this.description = description;
          this.isSelected=isSelected;
      }
  }
  </code></pre>