列表视图显示完美,但列表视图点击不起作用?


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();
}

}

从我在您的代码中查找的内容来看,您将意图键传递为 "名称">

intent.putExtra("name", json_string);

并且在请求您使用错误的键"json"时

json_string = getIntent().getExtras().getString("json");

相反,您应该使用

json_string = getIntent().getExtras().getString("name");

最新更新