wie man den Fortschrittsbalken (Kreis) in einer Aktivität mit einer Listenansicht anzeigt, bevor die Listenansicht mit Daten geladen wird
Ich habe eine ListView
in meinem zweiten activity.OnItemClick
von es ich rief ein webservice und versuchen, abrufen von Daten. Und danach bin ich bewegt, um Dritte Aktivität, die sich auch ListView
mit Beschreibung der bisherigen Aktivitäten ListView
Element.
Ich möchte die Anzeige eines Fortschritt-dialog, bevor das Auffüllen dieser ListView
.
Ich verstehe nicht, wie zu tun es auf ListView
? Weiß jemand, wie es zu tun?
Mein Code-
ThirdActivity.java
package com.google.iprotect;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParserException;
import com.google.iprotect.layout.TitleBarLayout;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.XmlResourceParser;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
public class ThirdActivity extends ListActivity implements OnItemClickListener{
JSONArray jArray1,jArray2;
String one,two,three,tablename;
String color,r;
JSONObject responseJSON;
TitleBarLayout titlebarLayout;
final ArrayList<Tables> arraylist = new ArrayList<Tables>();
TextView tableName;
ColorStateList colorStateList1;
String email1,password1;
protected void onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.thirdactivity);
ListView lv=getListView();
lv.setOnItemClickListener(this);
tablename=getIntent().getExtras().getString("Table Name");
email1 = getIntent().getExtras().getString("email");
password1 =getIntent().getExtras().getString("password");
titlebarLayout = new TitleBarLayout(ThirdActivity.this);
titlebarLayout.setLeftButtonText("go Back");
titlebarLayout.setRightButtonText("Logout");
titlebarLayout.setTitle(tablename);
titlebarLayout.setLeftButtonSize(70,40);
titlebarLayout.setRightButtonSize(70,40);
//titlebarLayout.setLeftButtonLeftDrawable(R.drawable.refresh);
//titlebarLayout.setRightButtonLeftDrawable(R.drawable.buttonrefresh);
//titlebarLayout.setLeftButtonBackgroundColor(Color.rgb(255,255,255));
//titlebarLayout.setRightButtonBackgroundColor(Color.rgb(34,49,64));
//titlebarLayout.setLeftButtonTextColor(Color.rgb(255,255,255));
//titlebarLayout.setRightButtonTextColor(Color.rgb(255,255,0));
XmlResourceParser parser1 =getResources().getXml(R.color.colorstatelist);
try {
colorStateList1 = ColorStateList.createFromXml(getResources(), parser1);
titlebarLayout.setRightButtonTextColor(colorStateList1);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
//TODO Auto-generated method stub
if (v.getId() == R.id.left_button) {
Intent intent = new Intent(ThirdActivity.this,SecondActivity.class);
intent.putExtra("email", email1);
intent.putExtra("password", password1);
startActivity(intent);
finish();
} else if (v.getId() == R.id.right_button) {
Intent intent = new Intent(ThirdActivity.this,
MainActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
ThirdActivity.this.startActivity(intent);
}
}
};
titlebarLayout.setLeftButtonOnClickListener(listener);
titlebarLayout.setRightButtonOnClickListener(listener);
updateTableList();
}
private void updateTableList() {
//TODO Auto-generated method stub
//final ProgressDialog pd1=ProgressDialog.show(this, "Calling Webservice", "Waiting...", true, false);
final ProgressBar pbHeaderProgress = (ProgressBar) findViewById(R.id.pbHeaderProgress);
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
//TODO Auto-generated method stub
super.onPreExecute();
pbHeaderProgress.setVisibility(View.VISIBLE);
}
protected Void doInBackground(Void... params) {
r = invokeWebService1(tablename);
//pd1.dismiss();
try {
responseJSON = new JSONObject(r);
//json reading
jArray1 = responseJSON.getJSONArray("FirstThree");//get JSONArray jArray1 from JSONObject with name FirstThree
jArray2 = responseJSON.getJSONArray("Color");//get JSONArray jArray2 from JSONOobject with name Color
JSONObject json_data1 = null;
JSONObject json_data2 = null;
for (int i = 0; i < jArray1.length(); i++) {
json_data1 = jArray1.getJSONObject(i);//get JSONObject json_data1 from JSONArray at index i;
one = json_data1.getString("One");//get value from JSONObject json_data1 with key "One"
two = json_data1.getString("Two");
three = json_data1.getString("Three");
json_data2 = jArray2.getJSONObject(i);
color = json_data2.getString("color");//get value from JSONObject json_data2 with key "color"
Tables tables = new Tables();
//set value to Tables Class
tables.column1 = one;
tables.column2 = two;
tables.column3 = three;
tables.tableName=tablename;
tables.color=color;
//add Tables object into ArrayList<Tables>
arraylist.add(tables);
Log.i("ONE", json_data1.getString("One"));
Log.i("TWO", json_data1.getString("Two"));
Log.i("THREE", json_data1.getString("Three"));
Log.i("color",""+ json_data2.getString("color"));
}
} catch (JSONException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
pbHeaderProgress.setVisibility(View.GONE);
//Custom Adapter for ListView
TableDetailAdapter adaptor = new TableDetailAdapter(ThirdActivity.this,
R.layout.table_data_list_item, arraylist);
setListAdapter(adaptor);
}
}.execute();
}
protected String invokeWebService1(String tablename2) {
//TODO Auto-generated method stub
String response = "";
try {
WebService webService = new WebService(
"http://sphinx-solution.com/iProtect/api.php?");
//Pass the parameters if needed
Map<String, String> params = new HashMap<String, String>();
params.put("action", "getTableRecords");
params.put("tablename", tablename2);
params.put("email", email1);
params.put("password", password1);
//Get JSON response from server the "" are where the method name
//would normally go if needed example
response = webService.WebGet("auth", params);
} catch (Exception e) {
Log.d("Error: ", e.getMessage());
}
return response;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//TODO Auto-generated method stub
Log.v("", "Click ListItem Number "+position);
Intent intent = new Intent(ThirdActivity.this,FourthActivity.class);
intent.putExtra("Json", responseJSON.toString());//sending json Object as a string to next activity
intent.putExtra("Table Name", tablename);
intent.putExtra("email", email1);
intent.putExtra("password", password1);
intent.putExtra("Item No", position);
startActivity(intent);
}
}
thirdactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linlaHeaderProgress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ThirdActivity" >
<include
android:id="@+id/titlebar"
layout="@layout/titlebar_layout" />
<ProgressBar
android:id="@+id/pbHeaderProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2" >
</ProgressBar>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="260dp"
android:layout_weight="5.04">
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="@dimen/titlebar_height"
android:layout_alignParentBottom="true"
android:background="@color/footer_bg_color"
android:gravity="bottom"
android:orientation="horizontal" >
<include
android:id="@+id/footer"
android:layout_height="@dimen/titlebar_height"
android:layout_gravity="bottom|center_horizontal"
layout="@layout/footer_layout" />
</LinearLayout>
</LinearLayout>
InformationsquelleAutor der Frage Ani | 2012-09-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
Gibt es mehrere Methoden, zeigt ein Fortschrittsbalken (Kreis) beim laden einer
activity
. In Ihrem Fall, eine mit einemListView
.IN DER ACTIONBAR
Wenn Sie mit einem
ActionBar
können Sie rufen Sie dieProgressBar
so aus (dies könnte gehen in IhremonCreate()
Und nachdem Sie fertig sind, wird die Anzeige der Liste, um es zu verbergen.
IM LAYOUT (XML)
Und in Ihrer Aktivität (Java)
Ich benutze einen AsyncTask zum abrufen von Daten für meine Listen. ALSO, in der AsyncTask ist
onPreExecute()
ich so etwas wie dieses:und in der
onPostExecute()
nach der Einstellung des Adapters an denListView
:EDIT: so sieht es in meiner app beim laden einer von mehreren
ListViews
InformationsquelleAutor der Antwort Siddharth Lele
Können Sie leichter tun.
Quelle: http://www.tutorialspoint.com/android/android_loading_spinner.htm
Es hat mir geholfen.
Layout:
InformationsquelleAutor der Antwort Sergey Kuchin
Ich diese für die Listen-Ansicht laden kann hilfreich sein.
activity_main.xml
und meine MainActivity-Klasse ist,
diese Aktivität den Fortschritt anzeigen für 3sec dann erscheint auf dem display listview, statt hinzufügen von Daten statisch zu Stringwerte Liste können Sie die Daten vom server in doInBackground() und anzeigen.
InformationsquelleAutor der Antwort Srinivas Rampelli
Sind Sie Verlängerung der ListActivity?
Wenn ja, legen Sie eine kreisförmige Fortschritt-dialog mit der folgenden Zeile in der xml -
Nun, die Fortschritt-Anzeige zeigt Ihnen, bis Sie haben alle Ihre listview-Informationen, und setzen Sie den Adapter. An welcher Stelle, es wird gehen Sie zurück in die Listenansicht, und der Fortschrittsbalken Weg gehen wird.
InformationsquelleAutor der Antwort The Holo Dev
Nutzen Sie bitte die Probe bei tutorialspoint.com. Die gesamte Implementierung muss nur ein paar Zeilen code ohne änderung der xml-Datei. Hoffe, das hilft.
SCHRITT 1: Import-Bibliothek
SCHRITT 2: Deklarieren ProgressDialog Globale variable
SCHRITT 3: Starten Sie einen neuen ProgressDialog und verwenden Sie die folgenden Eigenschaften (bitte beachten Sie, dass dieses Beispiel deckt nur die grundlegende Kreis-Ladebalken, ohne den Echtzeit-status).
SCHRITT 4: Wenn Sie mit AsyncTasks, können Sie Sie starten, zeigt der dialog in onPreExecute-Methode. Ansonsten, einfach den code in den Anfang der Schaltfläche onClick-Ereignis.
SCHRITT 5: Wenn Sie mit AsyncTasks, können Sie schließen, dem Fortschritts-dialog, indem Sie den code in der onPostExecute-Methode. Ansonsten, einfach platzieren Sie den code vor dem schließen der Schaltfläche onClick-Ereignis.
Es getestet mit meinem Nexus 5 android v4.0.3. Viel Glück!
InformationsquelleAutor der Antwort Chong Chern Dong
InformationsquelleAutor der Antwort Neel Kadia
Können Sie die
ProgressBar
zu listview-Fußzeile:...
layout/progress_bar.xml
wenn die Daten geladen, um die adapter anzeigen call:
InformationsquelleAutor der Antwort Abdulhamid Dhaiban
Erstellen einer xml-Datei einen beliebigen Namen (sagen progressBar.xml) in drawable
und fügen Sie
<color name="silverGrey">#C0C0C0</color>
im color.xml.Nun in Ihrer xml-Datei, wo Sie Ihre listView-Steuerelement fügen Sie diesen code:
In AsyncTask in der Methode:
Und in onPostExecute:
InformationsquelleAutor der Antwort Vaibhav Joshi
Schlage ich vor, die Ihnen beim arbeiten mit listview-oder recyclerview zu verwenden SwipeRefreshLayout. Wie diese
Nur wickeln Sie Ihre Ansicht, und dies wird eine animation erstellen von refresh beim laden von Daten oder durch swipping unten über den Bildschirm, wie können wir dies in vielen apps.
Hier ist die Dokumentation, wie es zu benutzen:
https://developer.android.com/training/swipe/add-swipe-interface.html
https://developer.android.com/training/swipe/respond-refresh-request.html
Happy coding !
InformationsquelleAutor der Antwort Gian Gomen
Ich bin mit diesem:
InformationsquelleAutor der Antwort Pratik Gondil