Please don't close this, IMHO it is decent and possibly useful programming question.
Please I am reading a lot of stuff, and I am getting confused because I read different opinions and different approaches.
The problem is the following:
in the getView()
of an Adapter
I need to perform some asynchronous operation, like checking an formation on the web, and update the view based on that.
I used the following approach:
every time getView()
is called I start a Thread
but my approach as earned me lots of criticism:
https://stackoverflow.com/a/28484345/1815311
https://stackoverflow.com/a/28484335/1815311
https://stackoverflow.com/a/28484351/1815311
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
//...
}
else {
//...
}
Thread th= new Thread(new Runnable() {
@Override
public void run() {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckSomeInfoOverTheInternet(url, new myCallback {
@Override
public void onSuccess() {
holder.textview.setText("OK");
}
@Override
public void onFailre() {
holder.textview.setText("NOT OK!!!!");
}
});
}
});
}
});
th.start();
return convertView;
}
Please what would be the best practice for doing such a thing?
Please note, I am not looking for a solution to execute the network requests in getView()
, but rather, how to updated the view depending on the result on the asynchronous call.