title: Android - where to put onClick on linearlayout of a fragment
body: <p>Obviously, I am new to Android - XML programming... So I have a navigation drawer, and once item is selected from the drawer, a corresponding fragment on the right side will display. Inside that fragment, I have linear layouts. I'd like to get redirected to another activity once that linear layout has been tapped. I was able to make it work on activities, by using android:onClick on XML file, but can't make it work on fragment. Somebody help me please.</p>
  
  <p>App interface, refer to this image:</p>
  
  <p><a href="http://i.stack.imgur.com/u6dHi.jpg" rel="nofollow">http://i.stack.imgur.com/u6dHi.jpg</a></p>
  
  <p><strong>Code:</strong></p>
  
  <p>fragment_smart.xml - the display once item's selected. I am trying to use the onClick on xml.</p>
  
  <pre><code>&lt;LinearLayout
      android:id="@+id/linearLayoutsmart1"
      android:layout_width="match_parent"
      android:layout_height="30dp"
      android:layout_below="@+id/smart_title"
      android:layout_marginLeft="15dp"
      android:layout_marginTop="15dp"
      android:orientation="horizontal"
      android:weightSum="1"
      android:onClick="smart_recommended_link"&gt;
  </code></pre>
  
  <p><strong>Here's my Java code:</strong></p>
  
  <pre><code>public class FragmentSmart extends Fragment {
  public static final String TAG = "stats";
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View myfragment = inflater.inflate(R.layout.fragment_smart, container, false);
      return myfragment;
  }
  
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
  }
  
  public void smart_recommended_link(View view) {
      Intent smartRecommendedIntent = new Intent(this, SmartRecommended.class);
      startActivity(smartRecommendedIntent);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The app is crashing when I clicked on the linearlayout using this code. What's the best thing to do here? Thank you!</p>