Ciao,stòcercando di visualizzare una ProgressBar per ogni riga della listview。 Hoest NPE in questa riga di codice:mProgress.setProgress(0);
似乎沒有找到ProgressBar。我在onCreate()中初始化PreogressBar。感謝您的幫助Android ProgressBar NPE
ListAdapter adapter = new ArrayAdapter<Dettaglio>(this, R.layout.dettaglio, R.id.tv_totale_group, dettagli){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView tvEn, tvCaa, tvPer;
tvEn = (TextView) row.findViewById(R.id.tv_to_group);
tvCaa = (TextView) row.findViewById(R.id.tv_cat_group);
tvPer = (TextView) row.findViewById(R.id.tv_perc_cat);
ProgressBar mProgress;
mProgress = (ProgressBar) findViewById(R.id.progress_e);
mProgress.setProgress(0);
mProgress.setMax(100);
Dettaglio d = dettagli.get(position);
tvCaa.setText(d.categorie+"");
double value = Double.valueOf(d.en);
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String en = formatter.format(value);
tvEn.setText(en+"");
//percent-------------------------
double totaleE = 0;
for (Dettaglio c : dettagli){
totaleE += c.en;
}
value = d.en/totaleE *100;
DecimalFormat decimalFormat = new DecimalFormat("0.#");
String en1 = decimalFormat.format(value);
tvPer.setText(en1+"%");
//----PROGRESS BAR----------------------------------------
int valore_per_barra = (int) Math.floor(value);
mProgress.setProgress(valore_per_barra);
return row;
}
};
lista.setAdapter(adapter);
其中'mProgress'初始化?方法onCreate() – Raghunandan
() mProgress =(ProgressBar)findViewById(R.id.progress_e); – user2996988