title: Buttons don't work in android fragments
body: <p>I'm working on an app and I have the following code:</p>
  
  <pre><code>package com.S.A.Productions.android.first;
  
  import com.S.A.Productions.android.first.R;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnClickListener;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class FirstActivity extends Fragment implements OnClickListener {
  
      int counter;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
  
                  View v = inflater.inflate(R.layout.lin, container, false);
  
          TextView temp = (TextView) v.findViewById(R.id.textView2);
  
          //Set the buttons
          Button button2 = (Button) v.findViewById(R.id.button2);
  
  
          //+++ BUTTON
          button2.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub//Get content of TextView
                  TextView temp = (TextView) v.findViewById(R.id.textView2);
                  //Convert the string to an integer
                  counter = Integer.parseInt(temp.getText().toString());
                  counter++;
                  temp.setText("" + counter);
                  String stringData = temp.getText().toString();
                  SharedPreferences.Editor editor = someData.edit();
                  editor.putString("sharedString", stringData);
                  editor.commit();
              }
  
          });
          //END OF +++ BUTTON
  
          return v;
      }
  
  
  }
  </code></pre>
  
  <p>But when I run the app and I click on that button the app crashes.
  I'm using the "v.findViewById"
  And at the end I return the v. So I don't know what exactly is wrong.
  Any ideas?</p>