Hi i m trying to load the list view from websrvice.. i m getting the
output in list when i m doing it alone but now in aSync task its
giving me error.. see the class file below
package com.example;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.http.ParseException;
import org.json.JSONException;
import com.spsoft.android.R;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class First extends Activity {
private ListView mainListView;
double latitude;
double longitude;
String places;
DownloadInfo downloadInfo;
JSONhelper jsoNhelper;
ProgressDialog dialog;
ArrayList<PlaceInformation> a;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
mainListView = (ListView) findViewById(R.id.mainListView);
Intent i = getIntent();
Bundle bun = i.getExtras();
latitude = bun.getDouble("lat");
Log.v("First", "latitude" + latitude);
longitude = bun.getDouble("lan");
places = bun.getString("places");
downloadInfo = new DownloadInfo();
downloadInfo.execute(First.this);
// Log.v("First", " arrayList length="+ a.size());
}
public void showListView() {
String[] stringArrayForList=new String[a.size()];
for (int j = 0; j < a.size(); j++) {
stringArrayForList[j]=a.get(j).toString();
}
ArrayAdapter<String> listAdapter = new
ArrayAdapter<String>(this,
R.layout.simplerow,stringArrayForList);
mainListView.setAdapter(listAdapter);
}
class DownloadInfo extends AsyncTask<Context, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
jsoNhelper = new JSONhelper(getApplicationContext(),
latitude,
longitude, places);
dialog = new ProgressDialog(First.this);
dialog.setMessage("Loading Please Wait");
dialog.show();
}
@Override
protected Void doInBackground(Context... params) {
//Looper.prepare();
try {
jsoNhelper.getJson();
a = jsoNhelper.resultArrayList;
// Log.i("in the do in background", "size is" +
a.size());
//onPostExecute(null);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Looper.loop();
return null;
}
@Override
protected void onPostExecute(Void result) {
try {
if (dialog.isShowing()) {
super.onPostExecute(result);
dialog.dismiss();
showListView();
}
} catch (Exception e) {
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en