I created a listview in Android, but now I am trying to allow the listview to be clickable to a new activity while passing parameters. The data for the listview is coming from an api. Code is below.
private static String urlString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_market_place);
urlString = "http://websiteforapi/api/market";
new ProcessJSON().execute(urlString);
}
private class ProcessJSON extends AsyncTask<String, Void, String> {
protected String doInBackground(String...strings){
String stream = null;
String urlString = strings[0];
HTTPDataHandler hh = new HTTPDataHandler();
stream = hh.GetHTTPData(urlString);
// Return the data from specified url
return stream;
}
protected void onPostExecute(String stream){
//..........Process JSON DATA................
if(stream !=null){
try {
// Get the full HTTP Data as JSONObject
JSONObject reader = new JSONObject(stream);
JSONArray businessArray = reader.getJSONArray("data");
ArrayList<String> businesses = new ArrayList<String>();
for(int i = 0; i < businessArray.length(); i++) {
JSONObject business_object_0 = businessArray.getJSONObject(i);
final String businessname = business_object_0.getString("name");
final String business = business_object_0.getString("business");
businesses.add(businessname);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(),android.R.layout.simple_list_item_1, businesses);
getListView().setAdapter(adapter);
}catch(JSONException e){
e.printStackTrace();
}
} // if statement end
} // onPostExecute() end
} // ProcessJSON class end
The JSON I am using from the API is this...
{"data":[{"id":"3","name":"My Test Business 3","phone":"6785555555","email":"business5@email.com","address":"123 This Avenue","city":"Atlanta","state":"GA","zip":"30308","business":"Technology 33333"},{"id":"4","name":"My Test Business 2 ","phone":"6783571004","email":"test100@test.com","address":"123 Some Street","city":"Lawrenceville","state":"GA","zip":"30043","business":"Website building"},{"id":"5","name":"My Test Business 3","phone":"6785555555","email":"business2@email.com","address":"123 This Avenue","city":"Atlanta","state":"GA","zip":"30308","business":"Technology 3"},{"id":"6","name":"My Test Business 5","phone":"6785555555","email":"business6@email.com","address":"123 This Avenue","city":"Atlanta","state":"GA","zip":"30308","business":"Technology 4"}]}
So far I can get the ListView to display, but so far I am unable to make them clickable to a new activity.