title: How to get Item View by position in GridView (in onCreateView )?
body: <p>I would like to get <strong>the item view by position in a GridView</strong>, and I don't know how to do it.</p>
  
  <p>I have tried to iterate over <strong>gridView.getChildCount()</strong>, but it returns 0 ( <a href="https://stackoverflow.com/a/8944678/1788704">https://stackoverflow.com/a/8944678/1788704</a> ).</p>
  
  <p>When I call <strong>gridView.getCount()</strong>, it returns 25 (the exact number of Items of my gridview). </p>
  
  <p>When I try to call <strong>getChildAt(position)</strong> in the loop with getCount, I get a NPE.</p>
  
  <p>What I want to do exactly is to get the item view to get 2 ImageView inside the item view and set a <strong>setOnClickListener() </strong> on each of them.</p>
  
  <p>At the moment, I set these listeners in the <strong>setOnItemClickListener()</strong> of the gridView.</p>
  
  <p>But the first time I click on my imageViews, the listener is not set, then it is okay (as it is initialized once the cell is clicked).</p>
  
  <pre><code>    @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
            [... ... ...]
  
            gridView.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                      int position, long id) {
  
                  ImageView shutterDown = (ImageView) v.findViewById(R.id.grid_item_shutter_down);
                  shutterDown.setOnClickListener(new OnClickListener() {
  
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getActivity(), "Down", Toast.LENGTH_SHORT).show();
                    }
                });
  
                  ImageView shutterUp = (ImageView) v.findViewById(R.id.grid_item_shutter_up);
                  shutterUp.setOnClickListener(new OnClickListener() {
  
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getActivity(), "Up", Toast.LENGTH_SHORT).show();
                    }
                });
  
  // The rest of the onItemClickListener (normal behavior).
              }
          });
      return rootView;
  }
  </code></pre>
  
  <p>Here is a screenshot of my grid cell :
  <img src="https://i.stack.imgur.com/y4WS7.png" alt="Grid cell"></p>