i found this resource http://www.embarcadero.com/rad-in-action/php-android
but could not found the solution Yet. Atif On Sat, Mar 5, 2011 at 2:17 PM, Atif Musaddaq <[email protected]>wrote: > Hi, All > > I would like to generate a List view in android (spinner) from the list i > will get from PHP server. > > right now my server code is like this. > > <?php > $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); > > echo json_encode($arr); > > ?> > > my android code is this. > > public class MainActivity extends Activity { > private Button btn; > private TextView txt; > //Change this IP:PORT with you current IP:PORT > private static String SERVICE_URL = "myurl"; > > private String getTheTimeFromJSONString(String json_string) > { > try { > JSONObject j = new JSONObject(json_string); > return j.getString("current_date"); > } catch (JSONException e) { > e.printStackTrace(); > return json_string; > } > } > private String execHttpRequest(String url) { > try { > HttpClient httpclient = new DefaultHttpClient(); > HttpGet httpget = new HttpGet(url); > //We want the JSON version of resource > httpget.addHeader("accept", "application/json"); > HttpResponse response = httpclient.execute(httpget); > HttpEntity entity = response.getEntity(); > return EntityUtils.toString(entity); > } catch (Exception e) { > e.printStackTrace(); > return e.getMessage(); > } > } > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > btn = (Button) findViewById(R.id.btn_click_me); > txt = (TextView) findViewById(R.id.txt); > btn.setOnClickListener(new View.OnClickListener() { > public void onClick(View arg0) { > String s = execHttpRequest(SERVICE_URL); > txt.setText(getTheTimeFromJSONString(s)); > } > }); > } > } > > > I would like to convert this response in java array or ArrayList so i can > use it to populate Spinner. May i know how i can do this. Right now i am > getting the response as seen in the output image attached with this message. > > Please help me in this regard. > > > > -- > Musaddaq > > > -- Atif Musaddaq Master in Media Informatics, RWTH Aachen & University of Bonn, Germany. [email protected] *”Design can be art. Design can be aesthetics. Design is so simple, that’s why it is so complicated.” —Paul Rand* -- 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

