Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 2.39 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to implement ProgresDialog [Android]
  2. public void onCreate(Bundle savedInstanceState) {
  3.     MyDialog = ProgressDialog.show(this, "Nalagam kanale" , "Prosimo počakaj ... ", true);
  4.     MyDialog.show();
  5. ... }
  6.        
  7. package com.TVSpored;
  8.  
  9. import java.util.ArrayList;
  10. import org.json.JSONArray;
  11. import org.json.JSONException;
  12. import org.json.JSONObject;
  13. import android.app.Activity;
  14. import android.app.ProgressDialog;
  15. import android.os.Bundle;
  16. import android.util.Log;
  17. import android.view.Menu;
  18. import android.view.MenuItem;
  19. import android.widget.ListView;
  20.  
  21.  
  22. public class Currently extends Activity{
  23. static final int PROGRESS_DIALOG = 0;
  24.  
  25. private ArrayList<CurrentlyItem> currentItems;
  26.  
  27. private CurrentAdapter aa;
  28. private ListView currentListView;
  29.  
  30. private JSONArray CurrentShows;
  31. private Communicator CommunicatorEPG;
  32.  
  33. /** Called when the activity is first created. */
  34. @Override
  35. public void onCreate(Bundle icicle) {
  36.     super.onCreate(icicle);    
  37.     setContentView(R.layout.layout_currently);
  38.  
  39.  
  40.     CommunicatorEPG = new Communicator();
  41.     currentItems = new ArrayList<CurrentlyItem>();
  42.  
  43.     if(currentItems == null)
  44.  
  45.     int resID = R.layout.current_item;
  46.     aa = new CurrentAdapter(this, resID, currentItems);
  47.  
  48.  
  49.     currentListView = (ListView)findViewById(R.id.currentListView);
  50.  
  51.     try {
  52.         currentListView.setAdapter(aa);
  53.     } catch (Exception e) {
  54.         Log.d(" * Napaka", e.toString());
  55.     }
  56.  
  57.  
  58.     try {
  59.         populateCurrent();
  60.     } catch (JSONException e) {
  61.         // TODO Auto-generated catch block
  62.         e.printStackTrace();
  63.     }
  64.  
  65. }
  66. public void populateCurrent() throws JSONException
  67. {
  68.     CurrentShows = CommunicatorEPG.getCurrentShows(0);
  69.  
  70.     for (int i = 0; i < CurrentShows.length(); i++)
  71.     {
  72.         JSONObject jsonObject = CurrentShows.getJSONObject(i);
  73.  
  74.           String start = jsonObject.getString("1");
  75.           Integer duration = jsonObject.getInt("2");
  76.           String title = jsonObject.getString("3");
  77.           String epg_channel = jsonObject.getString("4");
  78.           String channel_name = jsonObject.getString("5");
  79.           CurrentlyItem newItem = new CurrentlyItem(1, 2, 3, 4, 5);
  80.           currentItems.add(i, newItem);
  81.     }
  82. }
  83. }
  84.        
  85. new AsyncTask<Void, Void, Void> {
  86.   protected Long doInBackground(Void... voids) {
  87.     populateCurrent();
  88.   }
  89. }.execute()
  90.        
  91. runOnUiThread(new Runnable() {
  92.   public void run() {
  93.     currentItems.add(i, newItem);
  94.     aa.notifyDataSetChanged();
  95.   }
  96. }