我知道这是一个常见的问题.. 我读了这个网站和很多教程很多次但没有机会做工作。
那么代码是这样的:
public class mostraRisultatiActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mostra_risultati);
int cnt = 0;
final TableLayout tl = (TableLayout) findViewById(R.id.tabellaRisultati);
for (Esame e : Db.risposteDate){
TableRow tr = new TableRow(this);
TextView lbl1 = new TextView(this);
TextView lbl2 = new TextView(this);
TextView lbl3 = new TextView(this);
tr.setGravity(Gravity.CENTER);
lbl1.setGravity(Gravity.CENTER_VERTICAL);
lbl3.setGravity(Gravity.CENTER);
lbl1.setTextColor(android.graphics.Color.RED);
lbl2.setTextColor(android.graphics.Color.RED);
lbl3.setTextColor(android.graphics.Color.RED);
lbl1.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1 ) );
lbl2.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 7 ) );
lbl3.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1 ) );
lbl1.setText(e.getDomandaNum()+"");
lbl2.setText(Html.fromHtml(e.getTesto()+"<br />"));
lbl3.setText(e.getRispostaData());
tr.addView(lbl1);
tr.addView(lbl2);
tr.addView(lbl3);
tl.addView(tr);
if (e.getRispostaData() != null && e.getRispostaData().equals(e.getRispostaReale())){
cnt++;
lbl1.setTextColor(android.graphics.Color.GREEN);
lbl2.setTextColor(android.graphics.Color.GREEN);
lbl3.setTextColor(android.graphics.Color.GREEN);
}
}
double percentualeSucceso = (cnt*100)/Db.risposteDate.size();
final TextView risposteTotTV = (TextView) findViewById(R.id.risultatiTot);
final TextView riassuntorisTV = (TextView) findViewById(R.id.risRiassunto);
final TextView esitoTV = (TextView) findViewById(R.id.esito);
risposteTotTV.setText(Html.fromHtml("<b><big>TOT</big></b>" + "<br />" +
Db.risposteDate.size()));
riassuntorisTV.setText(Html.fromHtml("<b>Risposte corrette: </b>" +cnt+ "<br />" +
"Percentuale: "+percentualeSucceso+"%"));
if (percentualeSucceso >= 90) {
esitoTV.setText(Html.fromHtml("<b><big>Esito</big></b> <br />" +
"<small>PROMOSSO</small>"));
} else {
esitoTV.setText(Html.fromHtml("<b><big>Esito</big></b> <br />" +
"<small>BOCCIATO</small>"));
}
}
}
我在加载 ui 时想要一个进度条(特别是 for 循环)
我尝试了一个线程:所有工作,但没有进度显示,直到加载 ui(无用)我尝试使用 asyncTask 并且我总是异常崩溃。
任何的想法?