android populating gridivew from a url string
Posted
by
user1685991
on Stack Overflow
See other posts from Stack Overflow
or by user1685991
Published on 2012-10-01T09:31:34Z
Indexed on
2012/10/01
9:37 UTC
Read the original article
Hit count: 184
I am building an android application in which i am trying to read data from a url and want to display the data in a gridview. But i have some problem or dont understand to how to display the array list on grdiview. Here is my code for reading data from php url
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://sml.com.pk/a/smldb.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());
}
//paring data
double des;
double value;
try{
jArray = new JSONArray(result);
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
LAT=json_data.getDouble("TITLE");
LANG=json_data.getDouble("A");
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No Vehicles Found" ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
Here TITLE
and A
are my two columns of DB Table and i want to display them on gridview please any one help me to do this according to my current code.
Here is my live url for data string
http://sml.com.pk/a/smldb.php
© Stack Overflow or respective owner