title: Writing Click Event for a textview within a custom listview in android
body: <p>I am working on a project where there is a custom listview which has four TextViews in each row.When i click on a textview i want the color of the textview to change.I have tried by doing the code shown below:     </p>
  
  <pre><code>screenlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      final TextView slot1 = (TextView) view.findViewById(R.id.slot1);;
                      slot1.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                                  slot1.setTextColor(Color.RED);
                          }
                      });
  
  
                  }
              });
  </code></pre>
  
  <p>The issue is that it needs two clicks for the color to be set.How do i ensure that i get the color changed on the first click itself?.</p>
  
  <p>EDIT: I have added the adapter code below:</p>
  
  <pre><code>public class ScreenListAdapter extends BaseAdapter {
      List&lt;ScreensDataModel&gt;  list_screeen;
      Context con;
      LayoutInflater inflater;
      ViewHolder vh;
      ImageLoader imageLoader;
  
      List&lt;SlotsDataModel&gt; slot_list;
  
      public ScreenListAdapter(List&lt;ScreensDataModel&gt; list_screeen, Context con) {
          this.con=con;
          this. list_screeen= list_screeen;
          inflater=(LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          imageLoader = AppController.getInstance().getImageLoader();
      }
  
      @Override
      public int getCount() {
          return  list_screeen.size();
      }
  
      @Override
      public Object getItem(int position) {
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          if(convertView==null)
          {
              convertView=inflater.inflate(R.layout.screens_view_style, null);
              vh=new ViewHolder();
              vh.screenname= (TextView) convertView.findViewById(R.id.screenname);
              vh.moviename= (TextView) convertView.findViewById(R.id.moviename);
              vh.slots= (ViewGroup) convertView.findViewById(R.id.slotview);
              vh.slot1= (TextView) vh.slots.findViewById(R.id.slot1);
              vh.slot2= (TextView) vh.slots.findViewById(R.id.slot2);
              vh.slot3= (TextView) vh.slots.findViewById(R.id.slot3);
              vh.slot4= (TextView) vh.slots.findViewById(R.id.slot4);
  
  
  
              convertView.setTag(vh);
          }
          else
          {
              vh=(ViewHolder) convertView.getTag();
          }
          vh.screenname.setText(list_screeen.get(position).getScreenname());
          vh.moviename.setText(list_screeen.get(position).getMoviename());
          slot_list=list_screeen.get(position).list_slots;
          int i=slot_list.size();
          if(i==4)
          {
              vh.slot1.setText(slot_list.get(0).getTime()+"\n"+slot_list.get(0).getPrice());
              vh.slot2.setText(slot_list.get(1).getTime()+"\n"+slot_list.get(1).getPrice());
              vh.slot3.setText(slot_list.get(2).getTime()+"\n"+slot_list.get(2).getPrice());
              vh.slot4.setText(slot_list.get(3).getTime()+"\n"+slot_list.get(3).getPrice());
          }
          else if(i==3)
          {
              vh.slot1.setText(slot_list.get(0).getTime()+"\n"+slot_list.get(0).getPrice());
              vh.slot2.setText(slot_list.get(1).getTime()+"\n"+slot_list.get(1).getPrice());
              vh.slot3.setText(slot_list.get(2).getTime()+"\n"+slot_list.get(2).getPrice());
  
          }
          else if(i==2)
          {
              vh.slot1.setText(slot_list.get(0).getTime()+"\n"+slot_list.get(0).getPrice());
              vh.slot2.setText(slot_list.get(1).getTime()+"\n"+slot_list.get(1).getPrice());
  
  
          }
          else if(i==1)
          {
              vh.slot1.setText(slot_list.get(0).getTime()+"\n"+slot_list.get(0).getPrice());
          }
  
  
          vh.slot1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  vh.slot1.setBackgroundColor(Color.RED);
              }
          });
  
  
  
          convertView.setBackgroundColor(Color.parseColor("#2B030303"));
          return convertView;
  
      }
      public class ViewHolder
      {
  
       TextView screenname;
          TextView moviename;
          ListView slotlist;
          ViewGroup slots;
          TextView slot1;
          TextView slot2;
          TextView slot3;
          TextView slot4;
      }
  }
  </code></pre>