title: how to know when listview is finished loading data on android
body: <p>I currently have a list view that displays information of things that have to be done.</p>
  
  <p>When an user clicks the item on the listview, then the app checks which item has been clicked and set as done.</p>
  
  <p>If the item has been set as done, it will show an imageview with a check; this imageview is part of the item of the listview.</p>
  
  <p>everything is working well. If I scroll, exit the activity and open it again, uncheck the item, everything works well and shows or hide the imageview of the corresponding listview item.</p>
  
  <p>BUT my problem is that this:</p>
  
  <p>I have 2 buttons to sort the list view items, alphabetically and in order of date. When I click them, they work great. BUT, the app doesn't show the imageview of the items that have been checked.</p>
  
  <p>I know this is because in order to make the checks appear, I need the listview to be fully loaded. I mean, show in the activity with all the info.</p>
  
  <p>My question is:</p>
  
  <p>How can I know when the list view is done populating or loading, so that I can call the method that make sure which items have been check to show the image view?</p>
  
  <p>I have use isfocused(), onfocuschanged(), onWindowChangeState(), and all those type of methods, but none of them works to trigger my method.</p>
  
  <p>Is there any way to be able to know when the listview gets populated to make the check appear on the items that are been show, without any user interaction?</p>
  
  <p>Thanks for your time and help.</p>
  
  <p>PD: I already have the part where the user scroll the list, that part is taken care of.</p>
  
  <p>I'm using a SimpleCursorAdapter to fill the listview.</p>
  
  <p>This is where I fill the list view:</p>
  
  <pre><code>public void mostrarLista(){
  
          Cursor c = admin.obtenerCursorGastosFijos(ordenadoPor);
  
            // The desired columns to be bound
            String[] columnas = new String[] {"_id", "Descripcion", "Costo_Estimado", "Fecha_Pago"};
  
            // the XML defined views which the data will be bound to
            int[] views = new int[] {R.id.IdGstFijo, R.id.DescGstFijo, R.id.CostoGstFijo, R.id.FechaGstFijo };
  
            // create the adapter using the cursor pointing to the desired data 
            //as well as the layout information
            dataAdapter = new SimpleCursorAdapter(this, R.layout.lista_gastos_fijos, c, columnas, views, 0);
  
            listaGastos = (ListView) findViewById(R.id.listaGastosFijos1);
            // Assign adapter to ListView
            listaGastos.setAdapter(dataAdapter);
  
            listaGastos.setOnItemLongClickListener(new OnItemLongClickListener() {
  
                  @Override
                  public boolean onItemLongClick(AdapterView&lt;?&gt; Listview, View v,
                          int position, long id) {
                      // TODO Auto-generated method stub
                      Cursor cursor = (Cursor) Listview.getItemAtPosition(position);
  
  
                      String idGst=cursor.getString(cursor.getColumnIndexOrThrow("_id"));
  
                      dialogoOpcionesGst(Integer.parseInt(idGst), v).show();
  
  
                      return true;
                  }
                });
  
            listaGastos.setOnScrollListener(new OnScrollListener(){
  
              @Override
              public void onScroll(AbsListView arg0, int arg1, int arg2,
                      int arg3) {
                  // TODO Auto-generated method stub
              }
  
              @Override
              public void onScrollStateChanged(AbsListView arg0, int arg1) {
                  // TODO Auto-generated method stub
                  mostrarItemsPagados(listaGastos);
              }
  
            });
  
      }
  </code></pre>
  
  <p>This is the method that I did to navigate the items that are visible and see if they were checked or not</p>
  
  <pre><code>public void mostrarItemsPagados(ListView lista){
          for (int i = 0; i &lt;= lista.getLastVisiblePosition() - lista.getFirstVisiblePosition(); i++){
          View item = (View)lista.getChildAt(i);
          ImageView img = (ImageView)item.findViewById(R.id.imgPagado);
          if(admin.existeGstFijoReal(Integer.parseInt(((TextView)item.findViewById(R.id.IdGstFijo)).getText().toString()))){
              img.setImageResource(R.drawable.img_check);
          }
          else
              img.setImageDrawable(null);
          }
      }
  </code></pre>
  
  <p>this is the method I use to sort the list:</p>
  
  <pre><code>    public void ordenarNombre(View v){
          ordenadoPor=1;
          mostrarLista();
      }
  </code></pre>
  
  <p>and well, the layout of the item inside the list is:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" 
  &gt;
  
  &lt;TextView
      android:id="@+id/IdGstFijo"
      android:layout_height="match_parent"
      android:layout_width="0dp"
      android:layout_weight="2"
      android:visibility="gone"
      android:gravity="center"
      android:lines="4" /&gt;
  
  &lt;TextView
      android:id="@+id/DescGstFijo"
      android:layout_height="match_parent"
      android:layout_width="0dp"
      android:layout_weight="2"
      android:gravity="center"
      android:lines="4" /&gt;
  
   &lt;TextView
      android:id="@+id/CostoGstFijo"
      android:layout_height="match_parent"
      android:layout_width="0dp"
      android:layout_weight="2"
      android:gravity="center"
      android:lines="4"/&gt;
  
    &lt;TextView
      android:id="@+id/FechaGstFijo"
      android:layout_height="match_parent"
      android:layout_width="0dp"
      android:layout_weight="2"
      android:gravity="center"        
      android:lines="4" /&gt;
  
    &lt;ImageView
      android:id="@+id/imgPagado"
      android:layout_height="match_parent"
      android:layout_width="0dp"
      android:layout_weight="1"
  
      /&gt;
  </code></pre>
  
  <p></p>