0
I’m creating some Adapters in my app and I’ve come up with this question in a problem I’m having.
I have a code like:
public class ActivityCompra extends AppCompatActivity {
Adapter a;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compra);
//...
Thread busca = new Thread();
busca.execute();
fazOperacao3();
}
private class Thread extends AsyncTask<Void, Void, Boolean> {
@Override
protected void onPreExecute(){
//...
}
@Override
protected Boolean doInBackground(Void... params) {
//...
}
@Override
protected void onPostExecute(Boolean ok){
if(ok){
a = new Adapter();
lista.setAdapter(a);
cancel(true);
fazOperacao1();
fazOperacao2();
}
}
}
}
The functions fazOperacao1()
, fazOperacao2()
and fazOperacao3()
are executed before the ListView
be mounted, and only then getView is called to set the layout components.
I need to perform these operations after the view is all set up and I’m not sure how to do it.
I think it’s a very simple thing but I’m having a hard time.
Hello! Sorry for the delay to give a return. I did not understand very well what is happening in your code, could you explain? I need to run Asynktask before doing onPostExecute actions, because I do queries in the database and this data is used in the method
– Marcio
asynctask only executes onpostexecute after it is certain that doinbackground has been completed, even if it is network operations.
– Mr_Anderson