title: Listview listener not getting called
body: <p>I have button, which on clicked displays a listview and on clicking the listview item it must print something on logcat. I implemented this one in such a way that the list view and its listener are present inside the button onclick listener.</p>
  
  <p>All is working well except the listview listener is not getting called(i.e. nothing is printing on logcat when clicked on listview item)</p>
  
  <p>Here is my listener.</p>
  
  <pre><code>public class MyClickListener implements View.OnClickListener {
      LinearLayout parent;
      LayoutInflater layoutInflater;
      Context context;
      Home home;
  
      @Override
      public void onClick(View view) {
          parent = (LinearLayout) home.findViewById(R.id.main_view);
          View childLayout = layoutInflater.inflate(R.layout.mylayout, (ViewGroup) view.findViewById(R.id.list_layout));
          parent.addView(childLayout, 0);
  
          LinearLayout layout = (LinearLayout) home.findViewById(R.id.main_view);
          ListView list = (ListView) layout.findViewById(R.id.list);
          list.setAdapter(new MyListAdapter(context));
          lsit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                  System.out.println("hello Android");
              }
          });
      }
  }
  </code></pre>
  
  <p>mylayout.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/list_layout"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="15dp"&gt;
  
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/list"
          android:padding="15dp"
          android:divider="@android:color/transparent"
          android:dividerHeight="5dp"
          android:listSelector="@android:color/transparent"
          android:cacheColorHint="@android:color/transparent"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Home.java</p>
  
  <pre><code>public class Home extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);    
          setContentView(R.layout.home);
          Button button= (Button) findViewById(R.id.but);
          button.setOnClickListener(new MyClickListener(this,this,layoutInflater));
      }
  }
  </code></pre>
  
  <p>home.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:background="@color/background"&gt;
  ...
      &lt;LinearLayout
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_gravity="center"
          android:id="@+id/main_view"&gt;
      &lt;/LinearLayout&gt;
  .....
  </code></pre>
  
  <p>Can anyone help</p>
  
  <p>Edit 1</p>
  
  <p>MyListAdapter.java</p>
  
  <pre><code>private class MyListAdapter extends BaseAdapter {
          String[] items;
          LayoutInflater inflater;
          Context context;
  
          public MyListAdapter(Context context) {
              this.context = context;
              Resources resources = context.getResources();
              items = new String[]{resources.getString(R.string.q1), resources.getString(R.string.q2), resources.getString(R.string.q3)};
          }
  
          @Override
          public int getCount() {
              return items.length;
          }
  
          @Override
          public Object getItem(int i) {
              return i;
          }
  
          @Override
          public long getItemId(int i) {
              return i;
          }
  
          @Override
          public View getView(int i, View view, ViewGroup viewGroup) {
              View view1 = view;
              inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              if (view == null)
                  view1 = inflater.inflate(R.layout.list_layout_item, null);
              TextView question = (TextView) view1.findViewById(R.id.itemtext);
              question.setText(items[i]);
              return view1;
          }
      }
  </code></pre>
  
  <p>list_layout_item.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:id="@+id/item"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                style="@style/itemStyle"&gt;
  
      &lt;TextView
          android:id="@+id/itemtext"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:padding="8dp"
          android:drawableRight="@drawable/disclosure_indicator"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>