title: Android ImageButton worked well in Activity. It doesn't work in Fragment
body: <p>I'm trying to convert a layout so that it will include fragments.
  One of the views is an ImageButton that has a listener.
  The code worked fine as an Activity but makes trouble as a Fragment...</p>
  
  <p>First problem was that I couldn't use findViewById, 
  but I was able to find the answer for that here and fixed it with getView().</p>
  
  <p>I can't find an answer to the second problem...
  after I declared:</p>
  
  <pre><code>ImageButton camBt = (ImageButton)getView().findViewById(R.id.button1);
  </code></pre>
  
  <p>I want to set an on click listener:</p>
  
  <pre><code>camBt.setOnClickListener(listener);
  </code></pre>
  
  <p>But it keeps acting like the ImageButton (camBt) doesn't exist...
  I don't even know what's the problem... it worked fine in the Activity...</p>
  
  <p>Here's the full code.
  Many thanks!</p>
  
  <pre><code>public class CameraFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
      View V = inflater.inflate(R.layout.camera_fragment, container, false);
      return V;
  }
  
  ImageButton camBt = (ImageButton)getView().findViewById(R.id.button1);
  camBt.setOnClickListener(listener);
  
  ImageButton.OnClickListener listener = new ImageButton.OnClickListener()
  {
  
  @Override
  public void onClick(View arg0)
  {
  Camera.open().getParameters();
  }
  }; 
  }
  </code></pre>