Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I show progress bar before showing activity
    primarykey
    data
    text
    <p>Below is my java code and xml code. I want to show progress bar before showing any data. How can I do that? Im using asyntask for loading data. How will I show progressbar in my code to first show progressbar until data is loaded. When data is loaded, the progress bar is removed.</p> <pre><code>public class fifthscreen extends Activity { String num = null; TextView ingredient; long Menu_ID; String dish_name; View row4; View row3; String status; HorizontalListView listview; CategoryListAdapter3 cla; String DescriptionAPI; TextView txt1, txt2, txt3; ImageView img1; String URL, URL2; String SelectMenuAPI; static ArrayList&lt;Long&gt; Category_ID = new ArrayList&lt;Long&gt;(); static ArrayList&lt;String&gt; Category_name = new ArrayList&lt;String&gt;(); static ArrayList&lt;String&gt; Category_image = new ArrayList&lt;String&gt;(); public static String allergen2; private AQuery androidAQuery; String name; String description; String url1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fifthscreen); ingredient = (TextView) findViewById(R.id.ingredient); img1 = (ImageView) findViewById(R.id.test_button_image); txt1 = (TextView) findViewById(R.id.menuname); txt3 = (TextView) findViewById(R.id.description); Intent iGet = getIntent(); ImageView options = (ImageView) findViewById(R.id.options5); androidAQuery = new AQuery(this); options.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent iMenuList = new Intent(fifthscreen.this, LinkButtons.class); startActivity(iMenuList); } }); dish_name = iGet.getStringExtra("dish_name"); listview = (HorizontalListView) this.findViewById(R.id.listview2); cla = new CategoryListAdapter3(fifthscreen.this); new getDataTask().execute(); ImageView btnback = (ImageView) findViewById(R.id.btnback); btnback.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } void clearData() { Category_ID.clear(); Category_name.clear(); Category_image.clear(); } public class getDataTask extends AsyncTask&lt;Void, Void, Void&gt; { getDataTask() { } @Override protected void onPreExecute() { // TODO Auto-generated method stub } @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub parseJSONData(); return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub txt1.setText(name); txt3.setText(description); androidAQuery.id(img1).image(url1, false, false); listview.setAdapter(cla); } } public void parseJSONData() { SelectMenuAPI = Utils.dishdescription + dish_name; clearData(); URL = SelectMenuAPI; URL2 = URL.replace(" ", "%20"); try { HttpClient client = new DefaultHttpClient(); HttpConnectionParams .setConnectionTimeout(client.getParams(), 15000); HttpConnectionParams.setSoTimeout(client.getParams(), 15000); HttpUriRequest request = new HttpGet(URL2); HttpResponse response = client.execute(request); InputStream atomInputStream = response.getEntity().getContent(); BufferedReader in = new BufferedReader(new InputStreamReader( atomInputStream),8192); String line; String str = ""; while ((line = in.readLine()) != null) { str += line; } JSONObject json2 = new JSONObject(str); status = json2.getString("status"); if (status.equals("1")) { JSONArray school2 = json2.getJSONArray("data"); for (int i = 0; i &lt; school2.length(); i++) { name = school2.getJSONObject(0).getString("name"); description = school2.getJSONObject(0).getString( "description"); url1 = school2.getJSONObject(0).getString("image"); } JSONObject school3 = json2.getJSONObject("dish_nutrition"); final TableLayout table = (TableLayout) findViewById(R.id.table2); for (int j = 0; j &lt; school3.length(); j++) { String s = String.valueOf(j + 1); row3 = getLayoutInflater().inflate(R.layout.rows, null); ((TextView) row3.findViewById(R.id.localTime)) .setText(school3.getJSONObject(s).getString("qty")); ((TextView) row3.findViewById(R.id.apprentTemp)) .setText(school3.getJSONObject(s).getString("name")); fifthscreen.this.runOnUiThread(new Runnable() { public void run() { table.addView(row3); } }); } JSONArray school4 = json2.getJSONArray("dish_allergen"); // for (int i = 0; i &lt; school4.length(); i++) { JSONObject object = school4.getJSONObject(i); Category_ID.add((long) i); Category_name.add(object.getString("name")); Category_image.add(object.getString("image")); } final LinearLayout table3 = (LinearLayout) findViewById(R.id.table3); JSONArray school5 = json2.getJSONArray("dish_ingredient"); for (int i = 0; i &lt; school5.length(); i++) { row4 = getLayoutInflater().inflate(R.layout.row2, null); ((TextView) row4.findViewById(R.id.name)).setText(school5 .getJSONObject(i).getString("name")); ((TextView) row4.findViewById(R.id.subingredients)) .setText(school5.getJSONObject(i).getString( "sub_ingredients")); // table3.addView(row2); fifthscreen.this.runOnUiThread(new Runnable() { public void run() { table3.addView(row4); } }); } } else { JSONArray school2 = json2.getJSONArray("data"); for (int i = 0; i &lt; school2.length(); i++) { JSONObject object = school2.getJSONObject(i); Category_ID.add((long) i); Category_name.add(object.getString("name")); } } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block // IOConnect = 1; e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#E5E5E5" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/layoutbordercolor" &gt; &lt;ImageView android:id="@+id/btnback" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:paddingLeft="3dp" android:paddingTop="15dp" android:src="@drawable/back" android:visibility="gone" /&gt; &lt;ImageView android:id="@+id/bitmap" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:layout_weight="1.5" android:src="@drawable/logostar" /&gt; &lt;LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="4" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingTop="12dp" android:text="San Diego Unified" android:textColor="#603311" android:textSize="14sp" android:textStyle="bold" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="8dp" android:text="SCHOOL DISTRICT" android:textColor="#603311" android:textSize="10sp" /&gt; &lt;/LinearLayout&gt; &lt;ImageView android:id="@+id/options" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:paddingBottom="5dp" android:paddingTop="10dp" android:src="@drawable/options1" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/lytContent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="vertical" &gt; &lt;RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:background="@drawable/editbackground" android:paddingBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="8dp" android:paddingBottom="2dp" android:src="@drawable/search_btn" /&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="36dp" android:layout_toLeftOf="@+id/imageView1" android:layout_marginTop="5dp" android:paddingLeft="10dp" android:layout_marginLeft="10dp" android:paddingRight="5dp" android:gravity="left" android:background="#FFF" android:hint=" Search School by name" android:imeOptions="actionSearch" android:paddingTop="10dp" android:textSize="15dp" &gt; &lt;/EditText&gt; &lt;/RelativeLayout&gt; &lt;LinearLayout android:id="@+id/lytContent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/pleaseselect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:paddingLeft="15dp" android:text=" Select a school type" android:textColor="#0A2A1B" android:textSize="18sp" android:textStyle="bold" android:visibility="gone" /&gt; &lt;LinearLayout android:id="@+id/lytContent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop="10dp" android:background="@drawable/layout_border" android:orientation="vertical" &gt; &lt;ListView android:id="@+id/listMainMenuhome" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="3dp" android:paddingRight="3dp" android:dividerHeight="1dip" android:fadeScrollbars="true" android:listSelector="@color/listview_selector" android:visibility="gone" /&gt; &lt;/LinearLayout&gt; &lt;!-- android:listSelector="@drawable/listviewborder" --&gt; &lt;ProgressBar android:id="@+id/prgLoading" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /&gt; &lt;TextView android:id="@+id/txtAlert" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:paddingLeft="10dp" android:text="@string/alert" android:textColor="@color/text" android:textSize="14sp" android:visibility="gone" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload