在我的应用程序中,我管理大量数据并在列表视图中查看它们。数据很多我担心某些设备在打开Activity时很慢......我想添加一个进度对话框,用于在显示之前加载数据。你有这方面的例子吗?
private void showDetails(String anno){
SQLiteDatabase db = new BilancioHelper(this).getReadableDatabase();
final List<Dettaglio> dettagli = new ArrayList<Euscite.Dettaglio>(12);
for (int i=1; i<=12; i++){
String mese;
if (i<10){
mese = "0"+i;
} else {
mese = ""+i;
}
String sql = "SELECT _Id,Data,Categoria,Note,Uscita FROM Giornate WHERE uscita>0 AND data LIKE '"+anno+"-"+mese+"%'";
Cursor c = db.rawQuery(sql, null);
while (c.moveToNext()){
Dettaglio d = new Dettaglio();
d.id = c.getInt(0);
d.data = c.getString(1);
d.categorie = ( c.getString(2) != null ) ? c.getString(2) : "";
d.note = ( c.getString(3) != null ) ? c.getString(3) : "";
d.uscite = c.getFloat(4);
dettagli.add(d);
}
c.close();
}
db.close();
ListAdapter adapter = new ArrayAdapter<Dettaglio>(this, R.layout.dettaglio_row_uscite, R.id.tv_entrata, dettagli){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
Log.v("Bilancio", "Creo elemento in posizione "+position);
TextView tvData, tvNote, tvUscite, tvId, tvCategorie;
tvData = (TextView) row.findViewById(R.id.tv_data_uscita);
tvUscite = (TextView) row.findViewById(R.id.tv_entrata);
tvCategorie = (TextView) row.findViewById(R.id.tv_cat_uscite);
tvNote = (TextView) row.findViewById(R.id.tv_note_us);
tvId = (TextView) row.findViewById(R.id.tv_id_uscite);
Dettaglio d = dettagli.get(position);
tvData.setText(d.data+"");
tvNote.setText(d.note+"");
tvCategorie.setText(d.categorie+"");
Double value = Double.valueOf(d.uscite);
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String uscite = formatter.format(value );
tvUscite.setText(uscite+"");
tvId.setText(d.id+"");
return row;
}
};
lista.setAdapter(adapter);