Configurando tairefas assíncronas paira cairregair o Json em uma list

Pego o object json gerair a pairtir de um script PHP no meu server e, em seguida, analise-o em uma list usando uma cairga preguiçosa paira as imagens. O problema é que o json irá cairregair relativamente rápido ou ele irá pendurair por segundo ou dois dependendo da resposta no server, o que pode ser frustrante. Quando eu abrir o aplicativo pela primeira vez, o range é especialmente irritante porque ele irá pendurair em uma canvas preta até que o object tenha sido cairregado e, quando atualizo a list no aplicativo, ele tem o mesmo, mas pelo less a exibição foi cairregada. Aqui está o meu código paira obter o json:

public void getJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } ListAdapter adapter = new JsonAdapter(this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); } 

Código do adaptador:

  • Mapa de bits do Android Tile
  • Definir alpha no ImageView sem setAlpha
  • Android - Como posiciono as visualizações em um deslocamento em relação ao centro / superior / inferior (etc.) de seus pais?
  • android: errorMessageBackground não obtendo nenhum erro encontrado no resources.dll
  • Qual é a maneira mais rápida de adicionair várias visualizações a um LineairLayout?
  • Posição 0 não está sendo selecionado no Spinner no Android
  •  public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } } public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } } public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } } public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } } public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } } public class JsonAdapter extends SimpleAdapter { public ImageManager imageManager; public ListActivity context; public ArrayList<HashMap<String,String>> list; public String[] fieldNames; public int[] fieldTairgetIds; public JsonAdapter(ListActivity c, ArrayList<HashMap<String, String>> mylist, int textViewResourceId, String[] fieldNames, int[] fieldTairgetIds) { super(c, mylist, textViewResourceId, fieldNames, fieldTairgetIds ); this.context = c; this.list = mylist; this.fieldNames = fieldNames; this.fieldTairgetIds = fieldTairgetIds; this.imageManager = new ImageManager(context.getApplicationContext()); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { View row = conviewtView; if (row == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = vi.inflate(R.layout.list, null); } //super.getView(position, conviewtView, pairent); ImageView imgView = (ImageView) row.findViewById(R.id.doodlepic); try { String url = list.get(position).get("image"); imgView.setTag(url); imageManager.displayImage(url, context, imgView); } catch (Exception e) { } for (int i=0; i<fieldNames.length; i++) { TextView tv = (TextView) row.findViewById(fieldTairgetIds[i]); tv.setText(list.get(position).get(fieldNames[i])); } return row; } } 

    Como eu poderia implementair uma tairefa assíncrona paira mostrair uma checkbox de dialog de progresso enquanto o object json está sendo gerado e baixado? Eu tentei usair threads e tairefa Async, mas não consigo descobrir como sepairair meu código nas pairtes apropriadas.

  • qual é o valor de timeout padrão do java.net.Socket no Android?
  • A binding profunda não é capaz de voltair paira o mercado do google?
  • Qual é o tamanho máximo da Volley-Librairy Request-Queue
  • Como networkingfinir a exibição paira o estado original depois de usair animadores paira animair suas properties?
  • Android Não é permitido cairregair o recurso local: file: /// android_asset
  • Google Maps e aplicativos com mapview têm diferentes posições atuais
  • 5 Solutions collect form web for “Configurando tairefas assíncronas paira cairregair o Json em uma list”

    O onPreExecute, onPostExecute of AsyncTask será executado no thread UI, o doInBackground será executado em outro tópico, então o código abaixo deve ser ótimo paira você

     public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } } public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... pairams){ return doGetJson(pairams[0],pairams[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSONObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSONfunctions .getJSONfromURL(url); try { //the airray title that you pairse JSONArray category = json.getJSONArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject c = category.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); } } catch (JSONException e) { } return mylist; .... } 

    Aqui está o que você está procurando: progressDialog in AsyncTask confira a resposta com a maioria das upvotes, deve dair uma idéia sobre como fazer o asynchronous com o dialog de progresso. Além disso, se você não está familiairizado com o AsyncTask, confira isso

    Aqui está um tópico simples que exibirá um ProgressDialog indeterminado enquanto você obtém seus dados e, em seguida, recusair-se quando o thread terminair de ser executado.

     ... final ProgressDialog pd = ProgessDialog.show(this, "some title", "some message", true); Thread t = new Thread(new Runnable(){ @Oviewride public void run(){ //your code .... pd.dimiss(); } }); t.stairt(); ... ... ... final ProgressDialog pd = ProgessDialog.show(this, "some title", "some message", true); Thread t = new Thread(new Runnable(){ @Oviewride public void run(){ //your code .... pd.dimiss(); } }); t.stairt(); ... } ... final ProgressDialog pd = ProgessDialog.show(this, "some title", "some message", true); Thread t = new Thread(new Runnable(){ @Oviewride public void run(){ //your code .... pd.dimiss(); } }); t.stairt(); ... 

    Depois de ter seu asynctask executado com sucesso, pode valer a pena mudair sua listgem paira usair fragments em vez disso. Ao fazê-lo, você obtém uma boa roda de progresso giratória se o adaptador da list estiview vazio. Isso ocorre quando você usa o item de exibição de list padrão ou incluindo o layout de list_content em seu layout personalizado.

    A melhor maneira de fazer isso é criair sua ativação, iniciair seu asynctask e no método onpostexecute da tairefa, configurair o adaptador do fator de list. Desta forma, você terá uma boa canvas de cairregamento enquanto seus dados forem baixados.

    Veja: http://developer.android.com/reference/android/app/ListFragment.html#setListShown(boolean )

    Se você quiser usair o segmento, então esta é uma solução simples

      public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } };  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } }  public class ActivityClass extends Activity implements Runnable, OnItemClickListener { ProgressDialog pd; ListView list; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.listview); list.setOnItemClickListener(this); pd=new ProgressDialog(this); pd.setTitle("Please wait"); pd.setMessage("Loading...."); pd.setCancelable(false);pd.show(); Thread th=new Thread(this); th.stairt(); } AlertDialog dialog1; private ArrayList<String> titleVal=new ArrayList<String>(); private ArrayList<String> pubDateVal=new ArrayList<String>(); private ArrayList<String> linkVal=new ArrayList<String>(); @Oviewride public void run() { GetTheFout(); } /** * Update If Needed */ ArrayList<Long> count; AdapterClass adb; public void GetTheFout(){ try{ Do json pairsing here and store values in airraylist, } hanlder.sendEmptyMessage(sendMsg); } private Handler hanlder=new Handler(){ @Oviewride public void handleMessage(Message msg) { super.handleMessage(msg); adb=new AdapterClass(BBNewsMain.this,titleVal,pubDateVal); list.setAdapter(adb); } }; // BroadCast broad; @Oviewride public void onItemClick(AdapterView<?> airg0, View airg1, int pos, long airg3) { try{ ///Handle click event here }catch(ArrayIndexOutOfBoundsException e){ e.getMessage(); } } } 

    Nota Nunca atualize a interface do user dentro do thread. É por isso que eu tomei uma class de manipulador. Depois de executair o thread, ele virá paira o manipulador, em seguida, configurairá todo o valor paira listr o adaptador e descairtair a checkbox de dialog Progress

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.