Added loading dialog, using AsyncTask

master
unknown 13 years ago
parent 92044c1746
commit 49d509eb2f

@ -8,7 +8,7 @@
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:debuggable="false">
android:label="@string/app_name" android:debuggable="true">
<activity
android:label="@string/app_name"
android:name=".LeWebConnect"

@ -0,0 +1,16 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:gravity="center" android:orientation="vertical"
android:layout_height="fill_parent" android:background="#E5E5E5">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/main_loading" android:visibility="visible" android:layout_gravity="center">
</ProgressBar>
<ListView
android:id="@android:id/list"
android:layout_height="0dip" android:visibility="invisible" android:layout_width="wrap_content" android:layout_weight="1">
</ListView>
</LinearLayout>

@ -17,6 +17,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
</FrameLayout>
</LinearLayout>
</TabHost>

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TextView;

@ -14,9 +14,11 @@ import com.thinkit.lewebconnect.Attendee.LeWebByCountryComparator;
import com.thinkit.lewebconnect.Attendee.LeWebByLnameComparator;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.sax.Element;
import android.text.Editable;
@ -35,6 +37,7 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.Filterable;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
@ -52,62 +55,34 @@ public class Perticipents extends ListActivity {
private ArrayList<Attendee> users;
private EditText filterText = null;
ArrayAdapter<Attendee> adapter = null;
private ListView lv;
private Context mContext;
private ProgressDialog mDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String xml;
xml = XMLfunctions.getXML();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
//Log.d(TAG, "numResults length: " + String.valueOf(numResults));
mContext = this;
mDialog = new ProgressDialog(mContext);
setContentView(R.layout.perticipents);
if((numResults <= 0)) {
Toast.makeText(this, "Please make sure connection is available !", Toast.LENGTH_LONG).show();
finish();
}
NodeList nodes = doc.getElementsByTagName("user");
try {
users = new ArrayList<Attendee>();
//fill in the list items from the XML document
for (int i = 0; i < nodes.getLength(); i++) {
Node e = (Node)nodes.item(i);
users.add(NodeToAttendee(e));
}
Collections.sort(users, new LeWebByLnameComparator());
setContentView(R.layout.perticipents);
new getXmlTask().execute();
filterText= (EditText) findViewById(R.building_list.search_box);
filterText.addTextChangedListener(filterTextWatcher);
ListView lv = getListView();
lv = getListView();
lv.setFastScrollEnabled(true);
lv.setTextFilterEnabled(false);
registerForContextMenu(lv);
adapter = new LeWebAdapter(this, users, true, false, false);
setListAdapter(adapter);
registerForContextMenu(getListView());
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
@ -326,4 +301,57 @@ public class Perticipents extends ListActivity {
return user;
}
}
private class getXmlTask extends AsyncTask<Void, Void, ArrayList<Attendee>> {
@Override
protected void onPreExecute(){
mDialog.setMessage("Loading data");
mDialog.show();
}
@Override
protected ArrayList<Attendee> doInBackground(Void... params) {
// TODO Auto-generated method stub
String xml;
xml = XMLfunctions.getXML();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
//Log.d(TAG, "numResults length: " + String.valueOf(numResults));
if((numResults <= 0)) {
// Toast.makeText(this, "Please make sure connection is available !", Toast.LENGTH_LONG).show();
// finish();
return null;
}
NodeList nodes = doc.getElementsByTagName("user");
try {
users = new ArrayList<Attendee>();
//fill in the list items from the XML document
for (int i = 0; i < nodes.getLength(); i++) {
Node e = (Node)nodes.item(i);
users.add(NodeToAttendee(e));
}
Collections.sort(users, new LeWebByLnameComparator());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return users;
}
@Override
protected void onPostExecute(final ArrayList<Attendee> users){
adapter = new LeWebAdapter(mContext, users, true, false, false);
mDialog.hide();
setListAdapter(adapter);
registerForContextMenu(getListView());
}
}
}
Loading…
Cancel
Save