gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:41 25 4
gpt4 key购买 nike

<分区>

我目前有一个 ListView ,显示必须完成的事情的信息。

当用户点击 ListView 上的项目时,应用会检查哪个项目已被点击并设置为完成。

如果该项目已被设置为完成,它将显示一个带有检查的 ImageView ;此 ImageView 是 ListView 项目的一部分。

一切正常。如果我滚动,退出 Activity 并再次打开它,取消选中该项目,一切正常并显示或隐藏相应 ListView 项目的 ImageView 。

但我的问题是:

我有 2 个按钮可以按字母顺序和日期顺序对 ListView 项目进行排序。当我点击它们时,它们工作得很好。但是,应用程序不显示已检查项目的 ImageView 。

我知道这是因为为了显示支票,我需要完全加载 ListView 。我的意思是,在 Activity 中显示所有信息。

我的问题是:

我如何知道 ListView 何时完成填充或加载,以便我可以调用方法来确保已检查哪些项目以显示 ImageView ?

我使用了 isfocused()、onfocuschanged()、onWindowChangeState() 和所有这些类型的方法,但它们都无法触发我的方法。

有没有什么方法能够知道何时填充 ListView 以使检查出现在已显示的项目上,而无需任何用户交互?

感谢您的宝贵时间和帮助。

PD:我已经有了用户滚动列表的部分,该部分已处理完毕。

我正在使用 SimpleCursorAdapter 来填充 ListView 。

这是我填充 ListView 的地方:

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

});

}

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

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

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

    public void ordenarNombre(View v){
ordenadoPor=1;
mostrarLista();
}

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

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

/>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com