2017-08-27 18 views
0
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(); 
    } 


} 
+3

Sumit可以分享您遇到的错误? –

回答

1

从什么,我期待在你的代码要传递的意图键 “名”

intent.putExtra("name", json_string); 

,并同时要求你用错了钥匙“JSON”

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

相反,您应该使用

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

通过点击将listview的json数据传递给下一个活动 –