I\'m trying to list all the contacts in mobile. So far everything was working fine, but when I thought of running my code in AsyncTask
I\'m getting nothing on s
You can't touch views in Non-UI thread. You must set adapter in onPostExecute();
Use this: (Also, I hope that you keep your contacts somewhere, because I don't see contacts variable in your snippet)
new AsyncTask()
{
@Override
protected void onPreExecute()
{
pd = ProgressDialog.show(CallListActivity.this,
"Loading..", "Please Wait", true, false);
}// End of onPreExecute method
@Override
protected Void doInBackground(Void... params)
{
getContacts();
return null;
}// End of doInBackground method
@Override
protected void onPostExecute(Void result)
{
arrayAdapter = new ArrayAdapter(CallListActivity.this, R.layout.display_contacts,R.id.tv_single_contact_number,displayContactName);
lvCallList.setAdapter(new CustomAdapter(CallListActivity.this));
pd.dismiss();
}//End of onPostExecute method
}.execute((Void[]) null);