title: Change ListView Item Background on click - Android
body: <p>I've prepared a custom listview using BaseAdapter. Now I want to change color of selected item  of listview on click event. And multiple items should be selected. Here I am giving one demo :</p>
  
  <p><img src="https://i.stack.imgur.com/WW4vX.png" alt="enter image description here"></p>
  
  <p>Selected item's color is Orange. This is just a demo screen. If anybody knows to how change entire background color of a selected list item then please post their reviews. Thanks.</p>
  
  <p>I am using this BaseAdapter Class: </p>
  
  <pre><code>public class MyListAdapter extends BaseAdapter {
  
  private Activity activity;
  private String[] title, artist, duration, rowNumber;
  private static LayoutInflater inflater=null;
  ViewHolder holder;
  
  View vi;
  
  public MyListAdapter (Activity context, String[] songTitle,String[] songArtist, String[] songDuration )
  {
     try
     {
      activity = context;
      title = songTitle;
      artist = songArtist;
      duration = songDuration;
  
      rowNumber = new String[title.length];
      for(int i=0;i&lt;title.length; i++){
          rowNumber[i] = Integer.toString(i+1);
      }
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
     }
     catch (NullPointerException e) 
     {
         e.printStackTrace();
     }
  }
  
  public int getCount() {
      return title.length;
  }
  
  public Object getItem(int position) {
      return position;
  }
  
  public long getItemId(int position) {
      return position;
  }
  
  public static class ViewHolder{
      private TextView txtSongNumber, txtSongTitle, txtSongArtist, txtSongDuration;
  
  }
  
  public View getView(int position, View convertView, ViewGroup parent) 
  {
      try
      {
          vi=convertView;
  
         // System.out.println("Value of position"+position);
          if(convertView==null)
          {
              vi = inflater.inflate(R.layout.list_songs, null);
              holder=new ViewHolder();
              holder.txtSongNumber = (TextView)vi.findViewById(R.id.txtSongNumber);
              holder.txtSongTitle = (TextView)vi.findViewById(R.id.txtSongTitle);
              holder.txtSongArtist = (TextView)vi.findViewById(R.id.txtSongArtist);
              holder.txtSongDuration = (TextView)vi.findViewById(R.id.txtSongDuration);
  
              vi.setTag(holder);
          }
          else
  
              holder=(ViewHolder)vi.getTag();
  
          holder.txtSongNumber.setText(rowNumber[position]);
          holder.txtSongTitle.setText(title[position]);
          holder.txtSongArtist.setText(artist[position]);
  
          holder.txtSongDuration.setText(duration[position]);
  
      }
      catch (Exception e) 
      {
          e.printStackTrace();
      }
      return vi;
  }
  </code></pre>
  
  <p>}</p>