title: Android ListView with Two text and One CheckBox (eg. like a Setting)
body: <p>I'm creating Setting Activity which include two TextView and One CheckBox on right side. I have already done ListView. I want to be like when click on item and then check the CheckBox and again click on item then unchecked the CheckBox. How to implement CheckBox status?</p>
  
  <p>My Code.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>mport android.app.Activity;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.CheckBox;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  
  public class MainActivity extends ActionBarActivity {
      ListView list;
      String[] title = {
              "Google Plus",
              "Twitter",
              "Windows",
              "Bing",
              "Itunes",
              "Wordpress",
              "Drupal"
      };
      String[] descr = {
              "Social Network",
              "Social Network",
              "OS",
              "Search Engine",
              "Music",
              "Blog/Framework",
              "CMS"
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          CustomList adapter = new CustomList(MainActivity.this, title, descr);
          list = (ListView) findViewById(R.id.list);
          list.setAdapter(adapter);
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  CheckBox checkBox = (CheckBox)view.findViewById(R.id.checkBox);
                  if (checkBox.isChecked()){
                      checkBox.setChecked(false);
                  }else {
                      checkBox.setChecked(true);
                  }
  
                  Toast.makeText(MainActivity.this, "You Clicked at " + title[+position], Toast.LENGTH_SHORT).show();
              }
          });
  
  
      }
  
      private class CustomList extends ArrayAdapter&lt;String&gt; {
          private final Activity context;
          private final String[] title;
          private final String[] descr;
  
  
          public CustomList(Activity context,
                            String[] title, String[] descr) {
              super(context, R.layout.list_item, title);
              this.context = context;
              this.title = title;
              this.descr = descr;
          }
  
  
          @Override
          public View getView(final int position, View convertView, ViewGroup parent) {
  
              LayoutInflater layoutInflater = context.getLayoutInflater();
              View rowView = layoutInflater.inflate(R.layout.list_item, null, true);
              final TextView txtTitle = (TextView) rowView.findViewById(R.id.tv_title);
              TextView txtDescr = (TextView) rowView.findViewById(R.id.tv_descr);
  //            CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
              txtTitle.setText(title[position]);
              txtDescr.setText(descr[position]);
  
              return rowView;
          }
  
      }
  </code></pre>
  
  <p>main.xml</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="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_weight="1" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>list_item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:id="@+id/tv_title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="name"
          android:textSize="18sp" /&gt;
  
      &lt;TextView
          android:id="@+id/tv_descr"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/tv_title" /&gt;
  
      &lt;CheckBox
          android:id="@+id/checkBox"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:focusable="false"
          android:layout_alignParentRight="true" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>