title: Item click event of a custom ListView not working in Android
body: <p>We are working on a project where we have a custom listview and a baseadapter.We are trying to get the item click event of the listview.I pasted a toast within the item click listener in the activity and it is not showing.The following is the code that i have done.</p>
  
  <pre><code>question_list is the ListView Object.
  
  question_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                 // TextView example = (TextView) view.findViewById(R.id.single_question_name);
                //  String a=example.getText().toString();
                  Toast.makeText(MainActivity.this,"jo", Toast.LENGTH_LONG).show();
              }
          });
  </code></pre>
  
  <p>The data for the listview is added dynamically.We have used two dynamic layouts for inflation in the baseadapter.The code in the baseadapter is as follows:</p>
  
  <pre><code>public class QuestionAdapter extends BaseAdapter {
      ArrayList&lt;QuestionsDataModel&gt;  question_list_array;
      List&lt;OptionsDataModel&gt; option_list;
      Context context;
      LayoutInflater inflater;
      SingleHolder sh;
      int k=0,l=0;
      View v_single=null,v_multiple=null,v_final=null;
      MultipleHolder mh;
      int number_of_options;
      int position_counter=0;
      public  static  final  int TYPE_HEADER=0;
      public  static  final  int TYPE_ROW=1;
      public QuestionAdapter(ArrayList&lt;QuestionsDataModel&gt; question_list_array, Context context) {
          this.question_list_array=question_list_array;
          this.context=context;
          inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      }
  
      @Override
      public int getCount() {
          return question_list_array.size();
      }
  
      @Override
      public Object getItem(int position) {
          return null;
      }
  
      @Override
      public long getItemId(int position)
      {
          return 0;
      }
  
     @Override
      public int getViewTypeCount()
      {
          return 2;
  
      }
  
      @Override
      public int getItemViewType(int position) {
          return (question_list_array.get(position).getQuestion_type().equals("single"))?TYPE_HEADER :TYPE_ROW;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          String question_type = question_list_array.get(position).getQuestion_type();
          option_list = question_list_array.get(position).option_list;
          number_of_options = option_list.size();
  
          if (question_type.equals("single"))
          {
              v_single=convertView;
              if (v_single == null)
              {
                  v_single = inflater.inflate(R.layout.single_choice_layout, null);
                  sh = new SingleHolder();
                  sh.single_question_name = (TextView) v_single.findViewById(R.id.single_question_name);
                  sh.single_radiogroup = (RadioGroup) v_single.findViewById(R.id.single_radiogroup);
                  v_single.setTag(sh);
              }
              else
              {
                  sh = (SingleHolder) v_single.getTag();
              }
              sh.single_radiogroup.clearCheck();
              sh.single_radiogroup.removeAllViews();
              sh.single_question_name.setText(question_list_array.get(position).getQuestion_name());
              for (int j = 0; j &lt; number_of_options; j++)
              {
                  RadioButton rb = new RadioButton(context);
                  rb.setText(option_list.get(j).getOption_name());
                  sh.single_radiogroup.addView(rb);
              }
  
             v_final=v_single;
          }
  
  
  
        else if(question_type.equals("multiple"))
          {
  
              v_multiple = convertView;
              if (v_multiple == null) {
                  v_multiple = inflater.inflate(R.layout.multiple_choice_layout, null);
                  mh = new MultipleHolder();
                  mh.multiple_question_name = (TextView) v_multiple.findViewById(R.id.multiple_question_name);
                  mh.ll_multiple = (LinearLayout) v_multiple.findViewById(R.id.ll_multiple);
                  mh.ll_choice_child= (LinearLayout) v_multiple.findViewById(R.id.ll_choice_child);
                  v_multiple.setTag(mh);
  
              } else {
                  mh = (MultipleHolder) v_multiple.getTag();
              }
              mh.multiple_question_name.setText(question_list_array.get(position).getQuestion_name());
              mh.ll_choice_child.removeAllViews();
                  for (int m = 0; m &lt; number_of_options; m++)
                  {
                      CheckBox c = new CheckBox(context);
                      c.setText(option_list.get(m).getOption_name());
                      mh.ll_choice_child.addView(c);
                  }
  
  
              //return v;
              v_final=v_multiple;
  
          }
          return v_final;
      }
  
  
  
      private   class SingleHolder
      {
          TextView single_question_name;
          RadioGroup single_radiogroup;
  
      }
      private  class MultipleHolder
      {
          TextView multiple_question_name;
          LinearLayout ll_multiple;
          LinearLayout ll_choice_child;
      }
  }
  </code></pre>
  
  <p>EDIT:
  I have added the single item xml files:</p>
  
  <p>single_choice_layout.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="match_parent"
      android:orientation="vertical"
     &gt;
     &lt;TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/single_question_name"
        /&gt;
      &lt;RadioGroup
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/single_radiogroup"
          android:orientation="vertical"&gt;&lt;/RadioGroup&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>multiple_choice_layout.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="match_parent"
      android:id="@+id/ll_multiple"
      android:orientation="vertical"&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/multiple_question_name"
          android:text="second question"/&gt;
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/ll_choice_child"
          android:orientation="vertical"&gt;&lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>