I want to add item into listview using async task, so in doinbackgroud it will process and get the data one by one and then display it on listview one by one . But for my app doinbackground process all the data and then it will display into listview.
public class NewGetContacts extends AsyncTask<String[], Void, Void> {
private static final String TAG_TX = "txid";
private static final String TAG_FEE = "fees";
MyCustomAdapter mAdapter=new MyCustomAdapter();
ListView listViewHandle1 = (ListView) findViewById(R.id.listView2);
@Override
protected Void doInBackground(String[]... params) {
// TODO Auto-generated method stub
int len = params[0].length;
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
// String jsonStr;
mAdapter.addSeparatorItem("Transaction ...");
for(int i=0;i<len ;i++){
String turl = "https://coin/api/tx/"+params[0][i];
try {
String jsonStr1 = sh.makeServiceCall(turl, ServiceHandler.GET);
JSONObject jsonObj2 = new JSONObject(jsonStr1);
txtid = jsonObj2.getString(TAG_TX);
mAdapter.addItem("Transaction ID : "+txtid);
publishProgress();
}catch(Exception e){
Log.d("Exception In TXID -- >",e.getMessage());
}
}
return null;
}
protected void onProgressUpdate(Void... r) {
super.onProgressUpdate(r);
Log.d("Txid 14546465 ","--->");
mAdapter.notifyDataSetChanged();
listViewHandle1.requestLayout();
super.onProgressUpdate(r);
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
listViewHandle1.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
}