如何知道listview何时完成在android上加载数据

use*_*221 10 android listview

我目前有一个列表视图,显示必须完成的事情的信息.

当用户单击列表视图上的项目时,应用程序会检查已单击的项目并将其设置为已完成.

如果项目已设置为已完成,则会显示带有检查的图像视图; 此imageview是listview项目的一部分.

一切都运作良好.如果我滚动,退出活动并再次打开它,取消选中该项,一切正常,并显示或隐藏相应列表视图项的图像视图.

但我的问题是:

我有2个按钮来按字母顺序和日期顺序对列表视图项进行排序.当我点击它们时,它们工作得很好.但是,应用程序不会显示已检查项目的图像视图.

我知道这是因为为了使检查出现,我需要listview完全加载.我的意思是,在活动中显示所有信息.

我的问题是:

如何知道列表视图何时填充或加载,以便我可以调用确保已检查哪些项目以显示图像视图的方法?

我使用了isfocused(),onfocuschanged(),onWindowChangeState()以及所有这些类型的方法,但它们都不能用于触发我的方法.

是否有任何方法可以知道列表视图何时填充以使检查显示在已显示的项目上,而无需任何用户交互?

谢谢你的时间和帮助.

PD:我已经拥有用户滚动列表的部分,该部分已经完成.

我正在使用SimpleCursorAdapter来填充列表视图.

这是我填充列表视图的地方:

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<?> 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);
            }

          });

    }
Run Code Online (Sandbox Code Playgroud)

这是我用来导航可见项目并查看它们是否被选中的方法

public void mostrarItemsPagados(ListView lista){
        for (int i = 0; i <= 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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我用来排序列表的方法:

    public void ordenarNombre(View v){
        ordenadoPor=1;
        mostrarLista();
    }
Run Code Online (Sandbox Code Playgroud)

好吧,列表中项目的布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" 
>

<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" />

<TextView
    android:id="@+id/DescGstFijo"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="2"
    android:gravity="center"
    android:lines="4" />

 <TextView
    android:id="@+id/CostoGstFijo"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="2"
    android:gravity="center"
    android:lines="4"/>

  <TextView
    android:id="@+id/FechaGstFijo"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="2"
    android:gravity="center"        
    android:lines="4" />

  <ImageView
    android:id="@+id/imgPagado"
    android:layout_height="match_parent"
    android:layout_width="0dp"
    android:layout_weight="1"

    />
Run Code Online (Sandbox Code Playgroud)

use*_*221 2

好的,我设法解决这个问题。

我所要做的就是重写 getView 方法,如上所述。

但是,由于我使用 SimpleCursorAdapter 扩展类,所以我必须这样做:

public View getView(int position, View convertView, ViewGroup parent){

     View item = super.getView(position, convertView, parent);

     //Validation code for drawing or not the check image


     return item;
}
Run Code Online (Sandbox Code Playgroud)

这样,工作就完成了,现在每次重新排序、绘制或滚动列表视图时,视图都会正确刷新。

谢谢大家的帮助