title: How to start an intent from a linear layout on click inside a class extending fragment
body: <p>i have a navigation drawer layout created from a NavigationDrawerFragment which extends fragment.I have added <code>android:clickable="true"</code> inside a linear layout in fragment_navigation_drawer as shown below.However i am stuck on how or where to add OnClick event in my NavigationDrawerFragment,or should i do it in another class which extends activity?Thanks in advance.</p>
  
  <p>NavigationDrawerFragment.java:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class NavigationDrawerFragment extends Fragment {
      private ActionBarDrawerToggle mDrawerToggle;
      private DrawerLayout mDrawerLayout;
      private boolean mUserLearnedDrawer;
      private boolean mFromSavedInstanceState;
      public static final String PREF_FILE_NAME = "testpref";
      public static final String KEY_USER_LEARNED_DRAWER = "user_learned_drawer";
      private View containerView;
      private AdapterClass adapter;
      private RecyclerView recyclerView;
  
      public NavigationDrawerFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mUserLearnedDrawer = Boolean.valueOf(readFromPreferences(getActivity(), KEY_USER_LEARNED_DRAWER, "false"));
          if (savedInstanceState != null) {
              mFromSavedInstanceState = true;
  
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
          recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);
  
          adapter = new AdapterClass(getActivity(), getData());
          recyclerView.setAdapter(adapter);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          return layout;
  
  
      }
  
      public static List&lt;Information&gt; getData() {
          List&lt;Information&gt; data = new ArrayList&lt;&gt;();
          int[] icons = {R.drawable.ic_menu_check, R.drawable.ic_menu_check, R.drawable.ic_menu_check, R.drawable.ic_menu_check};
          String[] titles = {"Make up", "Lotions", "Deodorants", "Gels"};
  
          for (int i = 0; i &lt; titles.length &amp;&amp; i &lt; icons.length; i++) {
              Information current = new Information();
              current.iconId = icons[i];
              current.title = titles[i];
              data.add(current);
          }
          return data;
      }
  
      public void setUp(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
          containerView = getActivity().findViewById(fragmentId);
          mDrawerLayout = drawerLayout;
          mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
  
              @Override
              public void onDrawerOpened(View drawerView) {
                  super.onDrawerOpened(drawerView);
                  if (!mUserLearnedDrawer) {
                      mUserLearnedDrawer = true;
                      saveToPreferences(getActivity(), KEY_USER_LEARNED_DRAWER, mUserLearnedDrawer + "");
                  }
  
              }
  
  
              @Override
              public void onDrawerClosed(View drawerView) {
                  super.onDrawerClosed(drawerView);
  
  
              }
  
          };
          if (!mUserLearnedDrawer &amp;&amp; !mFromSavedInstanceState) {
              mDrawerLayout.openDrawer(containerView);
          }
          mDrawerLayout.setDrawerListener(mDrawerToggle);
          mDrawerLayout.post(new Runnable() {
              @Override
              public void run() {
                  mDrawerToggle.syncState();
              }
          });
      }
  
  
      @TargetApi(Build.VERSION_CODES.GINGERBREAD)
      public static void saveToPreferences(Context context, String preferenceName, String preferenceValue) {
          SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putString(preferenceName, preferenceValue);
          editor.apply();
      }
  
      public static String readFromPreferences(Context context, String preferenceName, String defaultValue) {
          SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
          return sharedPreferences.getString(preferenceName, defaultValue);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>fragment_navigation_drawer.xml:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#ffffff"
      tools:context="com.snappy.stevekamau.snappy.NavigationDrawerFragment"&gt;
  
      &lt;LinearLayout
          android:id="@+id/containerDrawerImage"
          android:layout_width="match_parent"
          android:orientation="vertical"
          android:layout_height="wrap_content"&gt;
  
          &lt;ImageView
              android:layout_width="280dp"
              android:layout_height="140dp"
              android:background="#000000"
              android:src="@drawable/header"&gt;&lt;/ImageView&gt;
          &lt;LinearLayout
              android:id="@+id/linear"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal"
              android:clickable="true"
              android:background="@drawable/linear_layout_clicked" &gt;
              &lt;ImageView
                  android:layout_width="50dp"
                  android:layout_height="50dp"
                  android:layout_centerVertical="true"
                  android:layout_marginLeft="15dp"
                  android:layout_marginRight="15dp"
                  android:src="@drawable/basket"/&gt;
              &lt;TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerVertical="true"
                  android:layout_gravity="center_vertical"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:layout_marginLeft="0dp"
                  android:text="My Basket"
                  android:textStyle="bold"
                  android:textColor="@color/colorSecondaryText"/&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="13dp"
              android:layout_marginTop="10dp"
              android:textStyle="bold"
              android:textSize="16dp"
              android:text="Categories" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:layout_below="@id/containerDrawerImage"
          android:id="@+id/drawerList"
          android:layout_marginTop="5dp"
          android:background="#ffffff"
          android:scrollbars="vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
      &lt;/android.support.v7.widget.RecyclerView&gt;
  &lt;/RelativeLayout&gt;</code></pre>
  </div>
  </div>
  </p>