0
我需要加載列表中的加載文本,但首先它應該加載一個空列表,在那段時間它應該顯示一個進度條。我從JSON進紙器獲取所有內容。但是我堅持在進程處於背景時如何加載空列表。如何使用emply list加載Android中的listview,稍後內容將會下載?
/**
* This class loads MainScreen in ListView
*/
package com.smartmedia.salonaudi;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.smartmedia.salonaudi.map.GoogleMapActivityClass;
/**
*
*
*
*/
public class SalonAudiActivity extends ListActivity {
Button map;
Button left;
Button about;
final Handler uiThreadCallback = new Handler();
Runnable runInUIThread;
// WebView about;
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> mylistCopy = mylist;
ArrayList<String> latitude = new ArrayList<String>();
ArrayList<String> longitude = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.listplaceholder);
//processDialog = ProgressDialog.show(this, "", getString(R.string.loading), true);
// getDetails();
// Map Button Click
map = (Button) findViewById(R.id.seeonmap);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(SalonAudiActivity.this,
GoogleMapActivityClass.class);
intent.putExtra("latitude", latitude);
intent.putExtra("longitude", longitude);
startActivity(intent);
}
});
// Live Button Click
about = (Button) findViewById(R.id.about);
about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://google.com"));
startActivity(intent);
}
});
JSONObject json = JSONfunctions
.getJSONfromURL("http://audi.smart-media.no/api/getEvents.php");
try {
JSONObject es = json.getJSONObject("events");
JSONArray event = es.getJSONArray("event");
JSONObject[] events = new JSONObject[es.length()];
for (int i = 0; i < event.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = event.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Time", "" + e.getString("startTime").split(" ")[0]);
map.put("startTime",
""
+ e.getString("startTime").split(" ")[1]
.substring(0, 5)
+ " @ Olympic Stadium");
map.put("title", "" + e.getString("title"));
System.out.println("title" + e.getString("title"));
map.put("ingress", "" + e.getString("ingress"));
map.put("description",
""
+ e.getString("description").replaceAll(
"\\<[^>]*>", ""));
map.put("image", "" + e.getString("image"));
map.put("latitude", "" + e.getString("latitude"));
map.put("longitude", "" + e.getString("longitude"));
System.out.println("latitude" + e.getString("latitude"));
mylist.add(map);
}
}
catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.main,
new String[] { "startTime", "title", "description" },
new int[] { R.id.time, R.id.title, R.id.description });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent();
intent.setClassName(SalonAudiActivity.this,
"com.smartmedia.salonaudi.DetailView");
HashMap<String, String> map = mylistCopy.get(arg2);
intent.putExtra("title", map.get("title"));
intent.putExtra("image", map.get("image"));
intent.putExtra("startTime", map.get("startTime"));
intent.putExtra("ingress", map.get("ingress"));
intent.putExtra("description", map.get("description"));
startActivity(intent);
}
});
for (int i = 0; i < mylist.size(); i++) {
HashMap<String, String> e = mylist.get(0);
latitude.add(e.get("latitude"));
longitude.add(e.get("longitude"));
}
}
public boolean isConnected() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
}
喜帕雷什ü可以給我一個示例演示項目.. – harish
嗨帕里斯它爲我工作感謝很多 – harish