i am working on an app, where i am getting response(Json) from my remote server.I am also able to parse and place markers based on that response.But i am failing in parsing ph data from response and passing it into another activity.
It is sending only phone number of last json object data in setOnInfoWindowClickListener event.
I know some minor modifications i have to made. Please suggest me in this.
This is the Json response i am getting.
[
{
id: 965,
distance: "1.47",
ph: "33441111",
name: "XYZ",
LS: " abcdef",
point: "77.588018,12.959282"
},
{
id: 965,
distance: "1.47",
ph: "33441111",
name: "XYZ",
LS: " abcdef",
point: "77.588018,12.959282"
},
.
.
]
I tried this way to parse
private class HttpGetTask extends AsyncTask<Void, Void, String> {
// Showing progress dialog
// Passing URL
@Override
protected String doInBackground(Void... params) {
// http stuff
}
@Override
protected void onPostExecute(String result) {
if (pDialog.isShowing())
pDialog.dismiss();
try {
JSONArray json = new JSONArray(result);
for (int i = 0; i < json.length(); i++) {
Log.v("Response", result);
final JSONObject e = json.getJSONObject(i);
String point = e.getString("point");
final String phone = e.getString("ph");
String[] point2 = point.split(",");
double lat1 = Double.parseDouble(point2[0]);
double lng1 = Double.parseDouble(point2[1]);
gMap.addMarker(new MarkerOptions()
.title(e.getString("name"))
.snippet(
e.getString("LS") + "*" + e.getString("ph"))
.position(new LatLng(lng1, lat1))
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.pmr)));
gMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public View getInfoContents(Marker mrkr) {
// TODO Auto-generated method stub
String name = mrkr.getTitle();
String detail = mrkr.getSnippet();
String trimmedDetail = detail.substring(0, 60);
Log.v("Info", name + " " + detail);
View v = getLayoutInflater().inflate(
R.layout.infowindow, null);
TextView title = (TextView) v
.findViewById(R.id.titleTV);
TextView snippet = (TextView) v
.findViewById(R.id.snippetTV);
title.setText("" + name);
snippet.setText("" + trimmedDetail);
return v;
}
});
gMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker arg0) {
Intent myIntent = new Intent(getBaseContext(),
DtActivity.class);
myIntent.putExtra("title", arg0.getTitle());
myIntent.putExtra("detail", arg0.getSnippet());
myIntent.putExtra("ph1", phone);
// How to access and send ph here.
try {
String ph = e.getString("ph");
myIntent.putExtra("ph", ph);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivity(myIntent);
}
});
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (null != mClient)
mClient.close();
}
}