내가 ListView에로 JSON 데이터를 분석하고, 성공적으로 내가 좋아, 홈페이지 위치의 목록을 표시하고 MainActivity.java에서 JSON의 첫 번째 수준을 분석하고 있습니다 :JSON 껍질 벗기기 - 표시하는 방법 두 번째 수준의 ListView
내부 위치
지금 내가 다음 SecondActivity에서이 목록에 델리를 표시해야합니다 내부 위치에 탭 않을 때마다 원하는
외부 위치, 같은 외부 Loc 데이에 간다 ations뿐만 아니라, 사용자가 탭이 미국을 보여줄 필요 할 때마다이 경우
같은JSON 모양 :
{
"all": [
{
"title": "Inner Locations",
"maps": [
{
"title": "Delhi",
"markers": [
{
"name": "Connaught Place",
"latitude": 28.632777800000000000,
"longitude": 77.219722199999980000
},
{
"name": "Lajpat Nagar",
"latitude": 28.565617900000000000,
"longitude": 77.243389100000060000
}
]
},
{
"title": "NCR",
"markers": [
{
"name": "Gurgaon",
"latitude": 28.440658300000000000,
"longitude": 76.987347699999990000
},
{
"name": "Noida",
"latitude": 28.570000000000000000,
"longitude": 77.319999999999940000
}
]
}
]
},
{
"title": "Outer Locations",
"maps": [
{
"title": "United States",
"markers": [
{
"name": "Virgin Islands",
"latitude": 18.335765000000000000,
"longitude": -64.896335000000020000
},
{
"name": "Vegas",
"latitude": 36.114646000000000000,
"longitude": -115.172816000000010000
}
]
}
]
}
]
}
참고 :하지만 난 처음 활동에서을 ListItem의에 탭 않을 때마다, 점점하지 SecondActivity의 모든 목록, 이유는 무엇입니까?
는 MainActivity.java:-
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://10.0.2.2/locations.json");
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("all");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrieve JSON Objects
map.put("title", jsonobject.getString("title"));
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(MainActivity.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, String.valueOf(position), Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
Intent sendtosecond = new Intent(MainActivity.this, SecondActivity.class);
// Pass all data rank
sendtosecond.putExtra("title", arraylist.get(position).get(MainActivity.TITLE));
Log.d("Tapped Item::", arraylist.get(position).get(MainActivity.TITLE));
startActivity(sendtosecond);
}
});
}
}
}
SecondActivity.java : 방법 아래
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.listview_main);
Intent in = getIntent();
strReceived = in.getStringExtra("title");
Log.d("Received Data::", strReceived);
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://10.0.2.2/locations.json");
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("maps");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrieve JSON Objects
map.put("title", jsonobject.getString("title"));
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
'strReceived'의 가치는 무엇입니까 – Raghunandan
@Raghunandan 올바른 값을 얻고 있습니다. 내부 위치를 탭한 다음 06-12 09 : 50 : 01.620 : D/Received Data :(4657) : 내부 위치 – Sophie
73 번 줄은 무엇입니까? – Raghunandan