final ListView listView= (ListView) findViewById(R.id.item);
ViewGroup headerView=(ViewGroup)getLayoutInflater().inflate(R.layout.header,listView,false);
listView.addHeaderView(headerView);
contactAdapter = new ContactAdapter(this,R.layout.row_layout);
listView.setAdapter(contactAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(News.this, details_Activity.class);
String json_string = (String) listView.getItemAtPosition(position);
intent.putExtra("name", json_string);
startActivity(intent);
}
});
json_string = getIntent().getExtras().getString("json");
try {
jsonObject = new JSONObject(json_string);
jsonArray = jsonObject.getJSONArray("server_response");
int count = 0;
String name,email,mobile;
while (count<jsonArray.length()) {
JSONObject JO = jsonArray.getJSONObject(count);
name = JO.getString("name");
email = JO.getString("email");
mobile = JO.getString("mobile");
Contacts contacts = new Contacts(name,email,mobile);
contactAdapter.add(contacts);
count++;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
从我在你的代码中看到的你传递意图密钥为 &#34;名称&#34;
intent.putExtra("name", json_string);
并且在请求您使用错误的密钥&#34; json&#34;
时json_string = getIntent().getExtras().getString("json");
相反,你应该使用
json_string = getIntent().getExtras().getString("name");