I was using the code from the doInBackground section to load a custom listview from a database and now that I have added it to an AsynchTask it shows nothing when the dialog has been dismissed. Does anyone know what I am doing wrong so that it will display my list when the progress bar dismisses again:
private class LoadList extends AsyncTask<String, UserRecord, JSONArray> {
protected JSONArray doInBackground(String... link) {
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://wallpaperapp.x10.mx/new.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
try{
jArray = new JSONArray(result);
JSONObject json_data=null;
displayname = new String[jArray.length()];
song_name = new String[jArray.length()];
artist = new String[jArray.length()];
description = new String[jArray.length()];
genre = new String[jArray.length()];
custom_genre = new String[jArray.length()];
album = new String[jArray.length()];
timestamp = new String[jArray.length()];
song_id = new int[jArray.length()];
avatar = new String[jArray.length()];
drawable = new Drawable[jArray.length()];
test_rating = new Float[jArray.length()];
songurl = new String[jArray.length()];
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
song_id[i]=json_data.getInt("id");
song_name[i]=json_data.getString("songname");
artist[i]=json_data.getString("artist");
displayname[i]=json_data.getString("displayname");
description[i]=json_data.getString("description");
genre[i]=json_data.getString("genre");
custom_genre[i]=json_data.getString("customgenre");
album[i]=json_data.getString("album");
timestamp[i]=json_data.getString("format");
avatar[i]=json_data.getString("image_url");
songurl[i]=json_data.getString("song_url");
drawable[i] = LoadImageFromWebOperations(avatar[i]);
test_rating[i] = (float) json_data.getDouble("rating");
user5 = new UserRecord(genre[i], displayname[i], timestamp[i], drawable[i], test_rating[i], songurl[i]);
publishProgress(user5);
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No results found." ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
return null;
}
protected void onProgressUpdate(UserRecord... progress) {
users.add(user5);
}
protected void onPostExecute(JSONArray jArray) {
dialog.dismiss();
}
protected void onPreExecute(){
dialog = ProgressDialog.show(mainmenu.this, "",
"Loading. Please wait...", true);
}
}
Here is my onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newsmain);
nameValuePairs = new ArrayList<NameValuePair>();
users = new ArrayList<UserRecord>();
ListView listView = (ListView) findViewById(R.id.ListViewId);
songname = (TextView) findViewById(R.id.tvTrack);
songimage = (ImageView) findViewById (R.id.imageView1);
playbutton = (Button) findViewById (R.id.playbutton1);
downloadbutton = (Button) findViewById (R.id.downloadbutton3);
listView.setAdapter(new UserItemAdapter(this, android.R.layout.simple_list_item_1, users));
flipper = (ViewFlipper) findViewById(R.id.tab2);
//when a view is displayed
flipper.setInAnimation(this,android.R.anim.fade_in);
//when a view disappears
flipper.setOutAnimation(this, android.R.anim.fade_out);
screenWidth = getResources().getDisplayMetrics().widthPixels;
new LoadList().execute();
}
The UserRecord that is getting published:
public class UserRecord {
public String genrez;
public String displaynamez;
public String timestampz;
public Drawable image_urlz;
public Float test_ratingz;
public String songurlz;
public UserRecord(String genrez, String displaynamez, String timestampz, Drawable image_urlz, Float test_rating, String songurlz) {
this.genrez = genrez;
this.displaynamez = displaynamez;
this.timestampz = timestampz;
this.image_urlz = image_urlz;
this.test_ratingz = test_rating;
this.songurlz = songurlz;
}
}
Adding this to my onPostExecute worked! I am so happy I figured it out.. thanks
listView.setAdapter(new UserItemAdapter(mainmenu.this, android.R.layout.simple_list_item_1, users));
#Override
protected void onPostExecute(String result) {
dialog.dismiss();
}
please put listview code in this function, means binding data to listview
Related
I wanted to retrieve the data from MySQL to android listView. I have follow each single steps from this tutorial, however it crashed when I trying to call JSON object. Please help. Thanks a lot..
private ListView listView;
String myJSON;
JSONArray information = null;
ArrayList<HashMap<String, String>> infoList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
infoList = new ArrayList<HashMap<String, String>>();
listView = (ListView) findViewById(R.id.listView2);
getData();
}
public void getData() {
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://192.168.107.115:80/Android/CRUD/retrieveInformation.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
#Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
information = jsonObj.getJSONArray(Config.TAG_RESULTS);
for(int i=0;i<information.length();i++){
JSONObject c = information.getJSONObject(i);
String date = c.getString(Config.TAG_DATE);
Toast.makeText(getApplicationContext(),date,Toast.LENGTH_LONG).show();
String timeIn = c.getString(Config.TAG_TiME_IN);
Toast.makeText(getApplicationContext(),timeIn,Toast.LENGTH_LONG).show();
String timeOut = c.getString(Config.TAG_TIME_OUT);
HashMap<String,String> info = new HashMap<String,String>();
info.put(Config.TAG_DATE, date);
info.put(Config.TAG_TiME_IN, timeIn);
info.put(Config.TAG_TIME_OUT,timeOut);
infoList.add(info);
}
ListAdapter adapter = new SimpleAdapter(
HomePage.this, infoList, R.layout.retrieve_data,
new String[]{Config.TAG_DATE,Config.TAG_TiME_IN,Config.TAG_TIME_OUT},
new int[]{R.id.date,R.id.timeIn,R.id.timeOut}
);
listView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
retrieveInformation.php
<?php
define('HOST','127.0.0.1:3307');
define('USER','root');
define('PASS','');
define('DB','androiddb');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect');
$sql = "select * from information";
$res = mysqli_query($con,$sql);
$result=array();
while($row=mysqli_fetch_array($res)){
array_push($result,array('id'=>$row[0],'name'=>$row[1],'weather'=>$row[2],'date'=>$row[3],'status'=>$row[4],
'time_in'=>$row[5], 'time_out'=>$row[6]));
}
print(json_encode(array("result"=>$result)));
mysqli_close($con);
?>
LogCat
Process: com.example.project.myapplication, PID: 31622
java.lang.NullPointerException
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.<init>(JSONObject.java:155)
at org.json.JSONObject.<init>(JSONObject.java:172)
at com.example.project.myapplication.GUI.HomePage.showList(HomePage.java:185)
at com.example.project.myapplication.GUI.HomePage$1GetDataJSON.onPostExecute(HomePage.java:176)
at com.example.project.myapplication.GUI.HomePage$1GetDataJSON.onPostExecute(HomePage.java:137)
at android.os.AsyncTask.finish(AsyncTask.java:632)
Code
`JSONObject jsonObj = new JSONObject(myJSON);` ,
class GetDataJSON extends AsyncTask<String, Void, String> {
and showList();.
Make a stupid mistake again. forget to switch on the wifi-connection
I have a listview populated by the data from mysql database. It works fine but when I select an item then press back , the previous listview fecth again data from database that duplicates the items in my listview.
Here's is my code :
public class CityPage extends Activity{
Activity context;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
ProgressDialog pd;
CityAdapter cityAdapter;
ListView listCity;
ArrayList<City> records;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_city_page);
context = this;
records = new ArrayList<City>();
listCity = (ListView) findViewById(R.id.cities);
cityAdapter = new CityAdapter(context, R.layout.city_layout, R.id.city_name, records);
listCity.setAdapter(cityAdapter);
listCity.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent myIntent = new Intent(view.getContext(),City_attractions.class);
Toast.makeText(CityPage.this, "Opening", Toast.LENGTH_LONG).show();
String info1 = records.get(position).getCityName();
String info2 = records.get(position).getDescription();
myIntent.putExtra("info1", info1);
myIntent.putExtra("info2", info2);
startActivity(myIntent);
}
});
}
#Override
protected void onStart() {
super.onStart();
fetchCity fetch = new fetchCity();
fetch.execute();
}
private class fetchCity extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
super.onPreExecute();
}
protected Void doInBackground(Void... params) {
InputStream is = null;
String result = "";
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://iguideph-001-site1.btempurl.com/getcity.php");
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// Get our response as a String.
is = entity.getContent();
} catch (Exception e) {
if (pd != null)
pd.dismiss(); //close the dialog if error occurs
Log.e("ERROR", e.getMessage());
}
//convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("ERROR", "Error converting result " + e.toString());
}
//parse json data
try {
// Remove unexpected characters that might be added to beginning of the string
result = result.substring(result.indexOf(""));
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
City p = new City();
p.setCityName(json_data.getString("place_name"));
p.setDescription(json_data.getString("description"));
records.add(p);
}
} catch (Exception e) {
Log.e("ERROR", "Error pasting data " + e.toString());
}
return null;
}
protected void onPostExecute(Void result) {
if (pd != null) pd.dismiss(); //close dialog
Log.e("size", records.size() + "");
cityAdapter.notifyDataSetChanged(); //notify the ListView to get new records
}
}
}
try remove those lines from onstart() and put them inside oncreate() function
fetchCity fetch = new fetchCity();
fetch.execute();
Good luck !
I am successfully retrieving but unable to put data into listview. how to update ui thread
after retrieving data.
here is the class of asynctask that retrieves data
I tried to update in onPostExecute but couldn't succeed.
class GetJson extends AsyncTask<String, Integer, ArrayList<RowItem>> {
ArrayList<RowItem> rowItems = new ArrayList<RowItem>();
//ArrayList<ArrayList<String>> fullscreens = new ArrayList<ArrayList<String>>() ;
public AsyncResponse delegate = null;
private CustomListViewAdapter arrayadapter;
private ProgressDialog pDialog;
private Context Mycontext;
private ArrayList<String> alist;
private ListView listView;
public GetJson(Context cnxt,ArrayList<String> alist, CustomListViewAdapter adapt,ListView listView) {
Mycontext = cnxt ;
//this.rowItems = rowItems;
this.alist = alist;
this.listView = listView;
}
#Override
protected void onPreExecute() {
// Showing progress dialog before sending http request
this.pDialog = new ProgressDialog(Mycontext);
this.pDialog.setMessage("Please wait..");
this.pDialog.setIndeterminate(true);
this.pDialog.setCancelable(false);
this.pDialog.show();
//alist.add("fifa");
}
#Override
protected ArrayList<RowItem> doInBackground(String... passing) {
here i am recieving data
return rowItems;
}
#Override
protected void onPostExecute(ArrayList<RowItem> Items) {
super.onPostExecute(Items);
this.pDialog.dismiss();
}
}
I laso tried runuithread in doinBackgroung method
there also i am getting runtime errors
here is my code
protected Void doInBackground(Void... unused) {
runOnUiThread(new Runnable() {
public void run() {
String result = null;
InputStream is = null;
JSONObject json_data=null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
JSONArray ja = new JSONArray();
List<NameValuePair> params = new LinkedList<NameValuePair>();
for(String s : alist)
{
Log.d("s",s);
params.add(new BasicNameValuePair("list[]",s));
}
try{
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
// 2. make POST request to the given URL
HttpGet httpPost = new HttpGet("http://10.0.3.2/infogamma/getapps.php?"+paramString);
// 4. convert JSONObject to JSON to String
String json = ja.toString();
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
//String json = EntityUtils.toString();
is = entity.getContent();
// Log.d("response", ");
}
catch(Exception e){
Log.i("taghttppost",""+e.toString());
}
//parse response
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder stringbuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
stringbuilder.append(line + "\n");
}
is.close();
result = stringbuilder.toString();
Log.d("ans",result);
}
catch(Exception e)
{
Log.i("tagconvertstr",""+e.toString());
}
//get json data
try{
//JSONObject json = new JSONObject(result);
JSONArray jArray = new JSONArray(result);
Log.d("app_lentgh", Integer.toString(jArray.length()));
for(int i=0;i<jArray.length();i++)
{
json_data = jArray.getJSONObject(i);
// this.donnees.add("title: "+ json_data.getString("title") + " appid: " + json_data.getString("appid") );
try{
//commmand http
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://10.0.3.2/infogamma/getAppDetails.php?appid="+json_data.getString("appid"));
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
//String json = EntityUtils.toString();
is = entity.getContent();
// Log.d("response", ");
}
catch(Exception e){
Log.i("taghttppost",""+e.toString());
}
//parse response
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.d("ans",result);
}
catch(Exception e)
{
Log.i("tagconvertstr",""+e.toString());
}
ArrayList<String> screenitem = new ArrayList<String>();
try{
JSONObject j = new JSONObject(result);
screenitem.add(j.getString("scr1"));
screenitem.add(j.getString("scr2"));
screenitem.add(j.getString("scr3"));
// this.fullscreens.add(screenitem);
// RowItem(ImageView imageId, String title, String desc,String catgs,String downloads,String rating,String discription)
RowItem item = new RowItem(j.getString("coverimage"), j.getString("title"), j.getString("category"),j.getString("downloads"),j.getString("rating"),
j.getString("scr1"),j.getString("scr2"),j.getString("scr3"),j.getString("discription"),j.getString("developer"),j.getString("price")
,json_data.getString("appid"));
rowItems.add(item);
}
catch(JSONException e){
Log.i("tagjsonexp",""+e.toString());
}
//SharedPreferences.Editor editor = ((Activity) Mycontext).getPreferences(Mycontext.MODE_PRIVATE).edit();
//editor.;
//editor.commit();
//Log.i("title",json_data.getString("title"));
}
}
catch(JSONException e){
Log.i("tagjsonexp",""+e.toString());
} catch (ParseException e) {
Log.i("tagjsonpars",""+e.toString());
}
adapt = new CustomListViewAdapter(getApplicationContext(),
R.layout.list_item, rowItems);
listView.setAdapter(adapt);
}});
return (null);
}
You can populate the list view from doInBackground by this code
runOnUiThread(new Runnable() {
public void run() {
//set listview Adapter here
}
});
this thing is not preferable. One more thing you can do is create a class which can hold the data you want to show on the item of a list and pass the array of that class object to onPostExecute method from where you can handle the UI thread.
Do it in onPostExecute() or if you want to add them from doInBackground() instantly, do it using runOnUiThread().
Edit:
After reading your comments, You are using CustomListViewAdapter, do you have a constructor with Context,int,ArrayList<String> as parameters in your adapter class?
In the application that I'm building, I have to load some datas from a database.
I load the datas when the user select an item from an alert dialog.
I use an AsyncTask class to connect to the database. Here's the code:
public class GetTask extends AsyncTask<Void,Void,Void>{
#Override
protected Void doInBackground(Void... arg0) {
getProdotti();
return null;
}
#Override
protected void onPostExecute(Void result) {
pg.dismiss();
for(int w=0;w<all_id.length;w++){
_id.add(all_id[w]);
nomi.add(all_names[w]);
foto.add(all_images[w]);
prezzi.add(all_prices[w]);
descr.add(all_desc[w]);
}
lista = (ListView)findViewById(R.id.lista_prodotti);
ListViewAdapter lva = new ListViewAdapter(nomi , foto , prezzi , _id , descr , context);
lista.setAdapter(lva);
}
protected void onPreExecute(Void result) {
pg = ProgressDialog.show(context, "", "Caricamento in corso...");
}
#Override
protected void onProgressUpdate(Void... values) {
}
}/**/
And i call it so
GetTask cat = new GetTask();
cat.execute();
The progress dialog is shown, but it doesn't disappear and the ListView is not populated.
What i'm doing wrong?
Here's getProdotti():
private void getProdotti(){
try{
httpclient = new DefaultHttpClient();
httppost = new HttpPost(host_url);
datas = new ArrayList<NameValuePair>(1);
datas.add(new BasicNameValuePair("categoria",selected));
Log.d("INVIO",selected);
httppost.setEntity(new UrlEncodedFormEntity(datas));
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
}catch (Exception e){
Toast.makeText(Catalogo.this, "error"+e.toString(), Toast.LENGTH_LONG).show();
}
if(inputStream != null){
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
result = sb.toString();
Log.d("RESULT",result);
}catch(Exception e){
Log.e("TEST", "Errore nel convertire il risultato "+e.toString());
}
try{
JSONArray jArray = new JSONArray(result);
all_id = new String[jArray.length()];
all_names = new String[jArray.length()];
all_prices = new String[jArray.length()];
all_images = new String[jArray.length()];
all_desc = new String[jArray.length()];
for(int i=0;i<jArray.length();i++){
JSONObject json_prod = jArray.getJSONObject(i);
Log.d("Debug",json_prod.getString("id_prodotto")+"--"+json_prod.getString("nome_prodotto"));
all_id[i]=json_prod.getString("id_prodotto");
all_names[i]=json_prod.getString("nome_prodotto");
all_prices[i]=json_prod.getString("prezzo");
all_images[i]=json_prod.getString("foto_prodotto");
all_desc[i]=json_prod.getString("descrizione");
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
}
Try adding lva.notifyDataSetChanged() inside onPostExecute like this :
lista = (ListView)findViewById(R.id.lista_prodotti);
ListViewAdapter lva = new ListViewAdapter(nomi , foto , prezzi , _id , descr , context);
lista.setAdapter(lva);
lva.notifyDataSetChanged();
Hope this helps, good luck ^^
Actually you have to tell the progress bar to disappear
you have tow ways
first
after setting the adapter to the list call
#Override
protected void onPostExecute(Void result) {
.....
pg.dismiss();
Or you can use handler
define a hanlder such
Handler handler = new Handler (){
#Override
protected void handleMessage(int what){
if(pg.isShowing()){
pg.dismiss();
}
}
}
And in onPostExecute method call
handler.sendEmptyMessage(0);
this will help !!!
i have a problem while im get the data from the server in text i can't converted into json object can not be converted into json array i just get the title and author from the database and show in list view
{"document":[{"id":"1","title":"complete refrence of android",
"author":"parag vyas","description":"lnvkzxhbkgbovdghognsdkhogjhlldnglj"}]}
plz help me
public class showalbooks extends Activity {
ArrayList<String> mylist = new ArrayList<String>();
String returnString="";
ListView listView ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showalbooks);
listView = (ListView) findViewById(R.id.mylist);
new LongRunningGetIO().execute();
}
private class LongRunningGetIO extends AsyncTask <Void, Void, String> {
protected String getASCIIContentFromEntity(HttpEntity entity) throws IllegalStateException, IOException {
InputStream in = entity.getContent();
StringBuffer out = new StringBuffer();
int n = 1;
while (n>0) {
byte[] b = new byte[4096];
n = in.read(b);
if (n>0) out.append(new String(b, 0, n));
}
return out.toString();
}
#Override
protected String doInBackground(Void... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://192.168.1.156/recess/document/document.json");
HttpClient client = new DefaultHttpClient();
HttpResponse response=null;
try{
response = client.execute(httpGet);
}
catch(Exception e){}
System.out.println(response.getStatusLine());
String text = null;
try {
response = httpClient.execute(httpGet, localContext);
HttpEntity entity = response.getEntity();
text = getASCIIContentFromEntity(entity);
} catch (Exception e) {
return e.getLocalizedMessage();
}
String var =text;
try{
JSONArray jArray = new JSONArray(var);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id: "+json_data.getString("id")+
", title: "+json_data.getString("title")
);
returnString += "\n" +"id:"+ json_data.getString("id")+" "+"Title:"+ json_data.getString("title");
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
listView.setFilterText(returnString);
return returnString;
}
protected void onPostExecute(String results) {
if (results!=null) {
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View listview,
int documentid, long documenttitle) {
// TODO Auto-generated method stub
}
});
}
}}}
The JSON array is enclosed by a JSON object, and has the id "document".
instead of:
JSONArray jArray = new JSONArray(var);
You should have:
JSONObject jObj = new JSONObject(var);
JSONArray jArray = jObj.getJSONArray("document");