title: How to get TextView item in GridView
body: <p>I have a list of numbers that the user can select. Once a number is selected, I want to save the selected state of the number and be able to restore the state of these numbers when the app restarts.</p>
  
  <p>Currently I have a hard time getting the items in the GridView to restore their state when the <code>onCreateView</code> is called. I tried call the <code>gridView.getChildCount()</code> and I notice it returns 0. I've read many threads with similar issue and tried their answer but have no success. I have been on this for a couple days already.</p>
  
  <p>Fragment1.java:</p>
  
  <pre><code>public class Fragment1 extends Fragment implements OnItemClickListener {
  
  public static final String ARG_SECTION_NUMBER = "section_number";
  
  private static final int START_NUM = 1;
  private static final int END_NUM = 59;
  public static boolean[] num_select = new boolean[END_NUM - START_NUM + 1];
  
  private static GridView gridView;
  private static NumberAdapter adapter;
  
  public Fragment1() {
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.fragment_1, container, false);
  
      gridView = (GridView) rootView.findViewById(R.id.gridview_number);
  
      adapter = new NumberAdapter(getActivity(), START_NUM, END_NUM);
      gridView.setAdapter(adapter);
      //gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
  
      gridView.setOnItemClickListener((OnItemClickListener) this);
  
      // ************* I NEED TO BE ABLE TO RESTORE THE NUMBER STATE HERE *******
  //restoreNumbers();
  
      return rootView;
  }   
  
  @Override
  public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
  
  num_select[position] = !num_select[position];
  
      if (num_select[position])
      {
          v.getBackground().setColorFilter(Color.rgb(210, 230, 230), 
      }
      else
      {
          v.getBackground().clearColorFilter();           
      }       
  }
  </code></pre>
  
  <p>NumberAdapter.java:</p>
  
  <pre><code>public class NumberAdapter extends BaseAdapter {
  private Context context;
  private int min_num;
  private int max_num;    
  
  public NumberAdapter(Context c, int num1, int num2) {
      this.context = c;        
      this.min_num = num1;
      this.max_num = num2;
  
      total_num = max_num - min_num + 1;       
  }    
  
  public View getView(int position, View convertView, ViewGroup parent) {
  
      TextView textView;
  
      if(convertView == null)
      {
          textView = new TextView(context);
          textView.setLayoutParams(new GridView.LayoutParams(GridView.AUTO_FIT, 85));
          textView.setTextSize(18.0f);
          textView.setGravity(0x11);
      }
      else
      {
          textView = (TextView) convertView;
      }    
  
      textView.setText(Integer.toString(position));
      textView.setBackgroundResource(R.drawable.number_deselect);  
  
      return textView;
  }
  
  public int getCount() {
      return total_num;
  }
  
  public Object getItem(int position) {
      return null;
  }
  
  public long getItemId(int position) {
      return position;
  }
  </code></pre>
  
  <p>}</p>