title: Change background color and font color of selected item in listview
body: <ul>
  <li>I want to change background color and font color when i select on particular row of listview</li>
  </ul>
  
  <p>MyAdapter class :</p>
  
  <pre><code>public class ListViewAdapter extends BaseAdapter {
  
      Context ctx;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist;
      LayoutInflater inflater;
  
      TextView a, b;
      String la, lb;
  
      String out;
      private int position_visible = -1;
  
  
      ListViewAdapter(Context ctx, ArrayList&lt;HashMap&lt;String, String&gt;&gt; arraylist) {
  
          this.ctx = ctx;
          this.arraylist = arraylist;
      }
  
  
      @Override
      public int getCount() {
          return arraylist.size();
      }
  
      @Override
      public Object getItem(int position) {
          return arraylist.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          inflater = (LayoutInflater) ctx
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          View itemView = inflater.inflate(R.layout.listitem, parent, false);
  
         a = (TextView) itemView.findViewById(R.id.a);
          b = (TextView) itemView.findViewById(R.id.b);
  
          tvPlaceName.setText(arraylist.get(position).get("a"));
  
          a = arraylist.get(position).get("a");
          b = arraylist.get(position).get("b");
  
          if (position_visible == position) {
              tvPlaceName.setBackgroundResource(R.color.divider);
              tvTime.setBackgroundResource(R.color.divider);
  
          } else {
              tvPlaceName.setBackgroundResource(R.color.white);
              tvTime.setBackgroundResource(R.color.white);
          }
  
          return itemView;
      }
  
      public void show(int position) { // show a delete button on swipe of list
          // item position
          position_visible = position;
          notifyDataSetChanged();
  
      }
  
      }
  </code></pre>
  
  <p>MyList.java :</p>
  
  <pre><code>private int posionClicked = -1;
  
    lv = (ListView) findViewById(R.id.listView);
  
  
  
       lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
              posionClicked = arg2;
              adapter.show(arg2);
          }
  </code></pre>
  
  <p>list.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:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#ffffff"
      android:orientation="horizontal"&gt;
  
  
      &lt;TextView
          android:padding="5dp"
          android:id="@+id/tvPlaceName"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:minLines="2"
          android:gravity="center_vertical"
          android:text="Large Text"
          android:textStyle="bold"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textColor="#0052a5"
          android:textSize="@dimen/font_large"
          android:background="@color/white"/&gt;
  
  
      &lt;TextView
          android:background="@color/white"
          android:padding="5dp"
          android:id="@+id/tvTime"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:gravity="bottom"
          android:text="Small Text"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:textColor="#0052a5" /&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>-- When user select any row of listview ,its background color and font color should be change. </p>
  
  <p>-- all suggestions are heartly welcome.</p>