Je mets à jour dynamiquement mon interface utilisateur grâce à une asynctask. Sur la méthode onpreexecute, je montre le progressdialog, mais il se montre tard. Je veux dire, je clique sur un bouton pour changer d'activité, puis l'interface est gelée, et après je vois brièvement le dialogue de progression et enfin mon interface utilisateur mise à jour.progressdialog s'affiche jusqu'à la fin (tâche asynchrone)
Quel est le problème dans mon code s'il vous plaît?
private ProgressDialog pd ;
@Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sqlview);
new taskDoSomething().execute();
}
private class taskDoSomething extends AsyncTask<Long, Integer, Integer>
{
protected void onPreExecute() {
// TODO Auto-generated method stub
pd = ProgressDialog.show(SQLView.this, "Working..", "Calculating", true,true);
}
protected Integer doInBackground(Long... params) {
UpdateIHM();
return 0;
}
protected void onPostExecute(Integer result) {
Toast.makeText(SQLView.this,"onPostExecute", Toast.LENGTH_LONG).show();
}
}
public void UpdateIHM()
{
runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout my_layout = (LinearLayout) findViewById(R.id.lil_content);
HotorNot info = new HotorNot(SQLView.this);
my_table data = new my_table();
Log.i("Test","ok 0");
info.open();
Log.i("Test","ok 0.1");
for(int i =0; i<3; i++){
data = info.getData();
for (int j=0; j<50; j++){
LinearLayout lil_temp = new LinearLayout(SQLView.this);
lil_temp.setOrientation(LinearLayout.HORIZONTAL);
lil_temp.addView(buildText(data.row), getParams(WRAP, WRAP));
lil_temp.addView(buildText(data.name), getParams(WRAP, WRAP));
lil_temp.addView(buildText(data.hotness), getParams(WRAP, WRAP));
my_layout.addView(lil_temp);
}
}
info.close();
handler.sendEmptyMessage(102);
}
});
}
si vous avez résolu votre problème plz mettre votre réponse.Je suis confronté au même problème. – Hemant