title: ListItem click not working in fragment in android
body: <p>I am working on a demo application and have used fragments in this demo,I have a listView with custom listItem in this listView,I want to capture the listItem's click event,I have tried lot many ways but nothing is happening,can anybuddy tell me whats wrong with my code,my code is as below:
  <strong>xml</strong>
  *</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;one.tusk.stush.views.PostListItem xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="@dimen/activity_vertical_margin"
      android:layout_marginLeft="@dimen/activity_horizontal_margin"
      android:layout_marginRight="@dimen/activity_horizontal_margin"
      android:layout_marginTop="@dimen/activity_vertical_margin" &gt;
      &lt;RelativeLayout
          android:id="@+id/relativeLayout1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_marginBottom="@dimen/activity_vertical_margin"
          android:layout_marginLeft="@dimen/activity_horizontal_margin"
          android:layout_marginRight="@dimen/activity_horizontal_margin"
          android:layout_marginTop="@dimen/activity_vertical_margin"
          android:background="#ffffff" &gt;
          &lt;View android:layout_width="50dp"
              android:layout_height="200dp"
              android:layout_alignParentRight="true"
              android:id="@+id/goodThing"
              android:layout_below="@+id/buttonLikes"/&gt;
          &lt;one.tusk.stush.views.PostGridItem
              android:id="@+id/imageViewPostImage"
              android:layout_width="match_parent"
              android:layout_height="150dp"
              android:layout_marginTop="0dp"
              android:adjustViewBounds="false"
              android:contentDescription="Post image"
              android:scaleType="centerCrop"
              android:src="@drawable/ic_launcher" /&gt;
  
              &lt;ProgressBar
          android:layout_width="match_parent"
           android:layout_marginTop="70dp"
          android:layout_height="150dp"
          android:id="@+id/loadingPost"
           /&gt;
  
          &lt;RelativeLayout
              android:id="@+id/profilelist"
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:layout_alignLeft="@id/imageViewPostImage"
              android:layout_alignRight="@id/imageViewPostImage"
              android:layout_below="@id/imageViewPostImage"
              android:alpha="1"
              android:background="#ffffff" &gt;
              &lt;RelativeLayout
                  android:id="@+id/photorelative"
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:layout_marginLeft="20dp"
                  android:layout_marginTop="7dp" &gt;
                  &lt;ImageView
                      android:id="@+id/imageViewUserImage"
                      android:layout_width="30dp"
                      android:layout_height="30dp"
                      android:adjustViewBounds="false"
                      android:contentDescription="User image"
                      android:maxHeight="30dp"
                      android:maxWidth="30dp"
                      android:minHeight="30dp"
                      android:minWidth="30dp"
                      android:scaleType="centerCrop"
                      android:src="@drawable/ic_launcher" /&gt;
                  &lt;ImageView
                      android:id="@+id/imageView1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:src="@drawable/avatar_overlay1" /&gt;
              &lt;/RelativeLayout&gt;
              &lt;Button
                  android:id="@+id/buttonComment"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginRight="15dp"
                  android:layout_toLeftOf="@+id/buttonLike"
                  android:background="@null"
                  android:drawableRight="@drawable/btn_comment" /&gt;
              &lt;Button
                  android:id="@+id/buttonShare"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="37dp"
                  android:layout_height="wrap_content"
                  android:layout_alignParentRight="true"
                  android:layout_marginRight="20dp"
                  android:background="@null"
                  android:drawableRight="@drawable/more" /&gt;
              &lt;Button
                  android:id="@+id/buttonLike"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="30dp"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_toLeftOf="@+id/buttonShare"
                  android:background="@null" /&gt;
              &lt;TextView
                  android:id="@+id/textViewUsername"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="55dp"
                  android:paddingTop="10dp"
                  android:text="ss"
                  android:textColor="#0c5d55"
                  android:textSize="15sp"
                  android:textStyle="bold" /&gt;
          &lt;/RelativeLayout&gt;
          &lt;TextView
              android:id="@+id/textViewPostText"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/profilelist"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="5dp"
              android:layout_marginTop="5dp"
              android:paddingBottom="5dp" /&gt;
          &lt;RelativeLayout
              android:id="@+id/commentandlike"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/textViewPostText"&gt;
              &lt;TextView
                  android:id="@+id/numbercomment"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_marginLeft="10px"
                  android:layout_toRightOf="@+id/buttonLikes"
                  android:text="11111"
                  android:textColor="#9f9f9f"
                  android:textSize="14dp" /&gt;
              &lt;Button
                  android:id="@+id/buttonLikes"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="wrap_content"
                  android:layout_height="16dp"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentTop="true"
                  android:layout_marginLeft="17dp"
                  android:layout_weight="0.60"
                  android:background="@null"
                  android:text="Likes"
                  android:textColor="#9f9f9f"
                  android:textSize="14dp" /&gt;
              &lt;TextView
                  android:id="@+id/textViewTimeAgo"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_alignParentRight="true"
                  android:layout_marginRight="15dp"
  
                  android:text="aggooooo"
                   android:textColor="#9f9f9f"
                  android:textSize="14dp" /&gt;
              &lt;View android:layout_width="1dp"
                  android:layout_height="10dp"
                  android:layout_below="@+id/buttonLikes"/&gt;
          &lt;/RelativeLayout&gt;
      &lt;/RelativeLayout&gt;
  &lt;/one.tusk.stush.views.PostListItem&gt;
  </code></pre>
  
  <p>*</p>
  
  <pre><code>public class TimelineFragment extends BaseFragment implements LoaderManager.LoaderCallbacks&lt;List&lt;Post&gt;&gt;, OnRefreshListener, OnScrollListener,OnItemClickListener {
  
      public static ListView mListViewTimeline;
  
  @Override
      public void onActivityCreated(Bundle savedInstanceState) {
  
          super.onActivityCreated(savedInstanceState);
          total = 0;
          mPullToRefreshLayout = (PullToRefreshLayout) getActivity().findViewById(R.id.ptr_layout);
          ActionBarPullToRefresh.from(getActivity()).allChildrenArePullable().listener(this).setup(mPullToRefreshLayout);
  
          mProgressBarLoading = (ProgressBar) getActivity().findViewById(R.id.progressBarLoading);
          mTextViewNoItems = (TextView) getActivity().findViewById(R.id.textViewNoItems);
  
          mTimelineAdapter = new TimelineAdapter(getActivity());
  
          mListViewTimeline = (ListView) getActivity().findViewById(R.id.listViewTimeline);
          mListViewTimeline.setEmptyView(mProgressBarLoading);
          mListViewTimeline.setAdapter(mTimelineAdapter);
  
          mListViewTimeline.setOnScrollListener(this);
  
          //  mListViewTimeline.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
          mListViewTimeline.setVerticalScrollBarEnabled(false);
  
          mListViewTimeline.setOnItemClickListener(this);
  
          final Activity activity = getActivity();
  
          if(activity != null) {
              final Handler handler = new Handler();
              handler.postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      getLoaderManager().initLoader(0, null, TimelineFragment.this);
                      //Do something after 100ms
                  }
              }, 1000);
  
  
  
              mTextViewNoItems.setOnClickListener(new OnClickListener() {
                  @Override
                  public void onClick(final View v) {
                      getLoaderManager().destroyLoader(0);
  
                      getLoaderManager().initLoader(0, null, TimelineFragment.this);
                      Log.d("CLICK", "REFRESH");
  
                  }
              });
          }
  
      }
  @Override
      public void onItemClick (AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
          Intent intentPostDetail = new Intent(getActivity(), PostDetailActivity.class);
          Post post = mTimelineAdapter.getItem(position);
          intentPostDetail.putExtra("Post", post);
          startActivity(intentPostDetail);
      }
  }
  
  **timelineadapter**
  
  package one.tusk.stush.adapters;
  
  import java.util.List;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  
  import com.company.stush.R;
  import one.tusk.stush.connect.Post;
  import one.tusk.stush.views.PostListItem;
  
  public class TimelineAdapter extends ArrayAdapter&lt;Post&gt; {
  
      private final LayoutInflater mInflater;
  
      public TimelineAdapter(Context context) {
  
          super(context, R.layout.list_item_post);
          mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      public void setData(List&lt;Post&gt; data) {
          setNotifyOnChange(false); 
          clear();
          if (data != null) {
              addAll(data);
              notifyDataSetChanged();
          }
      }
  
      @Override 
      public View getView(final int position, View convertView, ViewGroup parent) {
  
          Post post = getItem(position);
          PostListItem view;
          if (convertView == null) {
              view =  (PostListItem) mInflater.inflate(R.layout.list_item_post, parent, false);
          } else {
              view = (PostListItem) convertView;
          }
          view.setPost(post);
          return view;
      }
  }
  </code></pre>