我目前有一个列表视图,显示必须完成的事情的信息。
当用户单击列表视图上的项目时,应用程序会检查已单击的项目并将其设置为已完成。
如果该项目已设置为完成,它将显示一个带有检查的图像视图;此图像视图是列表视图项目的一部分。
一切正常。如果我滚动,退出活动并再次打开它,取消选中该项目,一切正常并显示或隐藏相应列表视图项目的图像视图。
但我的问题是:
我有 2 个按钮可以按字母顺序和日期顺序对列表视图项进行排序。当我点击它们时,它们工作得很好。但是,该应用程序不显示已检查项目的图像视图。
我知道这是因为为了使检查出现,我需要完全加载列表视图。我的意思是,在活动中显示所有信息。
我的问题是:
我如何知道列表视图何时完成填充或加载,以便我可以调用确保已检查哪些项目以显示图像视图的方法?
我使用了 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);
}
});
}
这是我用来导航可见项目并查看它们是否被选中的方法
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"
/>