问题描述
我试图从一个活动发送JSON对象数据到其他的活动。我有一个成功的从一个JSON数组填充一个列表视图,但正如我在一个列表项单击,它没有响应。正在对项目点击执行任何操作。我看到一些教程,但它并没有帮助。我需要的列表项的JSON数据发送到另一个活动。任何帮助将是AP preciated。
的ListView填充使用JSON的活动。
{尝试 jArray =新JSONArray(结果);
ListView控件的ListView =(ListView控件)findViewById(R.id.listtour_cat);
listView.setAdapter(新ListViewAdapter(JSONUseActivity.this,jArray));
listView.setOnItemClickListener(新OnItemClickListener(){ @覆盖
公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,
长ARG3){
// TODO自动生成方法存根
尝试{
如果(!jArray.isNull(ARG2)){
意向意图=新意图(getApplicationContext(),TourDetailActivity.class);
intent.putExtra(ID,jArray.optJSONObject(ARG2).getString(tour_id));
startActivity(意向);
} }
赶上(JSONException E){
Log.e(log_tag,错误分析数据+ e.toString());
} }
});
}
赶上(JSONException E){
Log.e(log_tag,错误分析数据+ e.toString());
} }
赶上(例外五){
Log.e(log_tag,在HTTP连接错误!+ e.toString());
}
目标活动:
意向意图= getIntent();
字符串rcvid = intent.getStringExtra(ID);
Toast.makeText(getApplicationContext(),rcvid,Toast.LENGTH_LONG).show();
转换JsonArray为字符串,然后将其连接到意向ANS发送。
的JSONObject jObject =新的JSONObject(你的JSON响应); 意图obj_intent =新意图(Main.this,Main1.class);
束B =新包();
b.putString(阵列,jObject4.toString());
obj_intent.putExtras(二);
在哪里jObject4是JSON对象。
获取下一页:
意图B = getIntent()getExtras()。
字符串数组= b.getString(阵列);
I am trying to send the json object data from one activity to other activity. I have a listview that is successfully populated from a json array, but as i click on a list item, it is not responding. No action is being performed on item click. I saw some tutorials but it did not helped. I need to send the list item's json data to another activity. Any help would be appreciated.
Activity of listview populated with Json.
try{
jArray = new JSONArray(result);
ListView listView=(ListView)findViewById(R.id.listtour_cat);
listView.setAdapter(new ListViewAdapter(JSONUseActivity.this,jArray));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
try{
if(!jArray.isNull(arg2)){
Intent intent = new Intent(getApplicationContext(),TourDetailActivity.class);
intent.putExtra("id", jArray.optJSONObject(arg2).getString("tour_id"));
startActivity(intent);
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
});
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
catch (Exception e) {
Log.e("log_tag","Error in http connection!!" + e.toString());
}
Target Activity:
Intent intent = getIntent();
String rcvid = intent.getStringExtra("id");
Toast.makeText(getApplicationContext(), rcvid, Toast.LENGTH_LONG).show();
Convert JsonArray to String then attach it to Intent ans send it.
JSONObject jObject = new JSONObject("Your Json Response");
Intent obj_intent = new Intent(Main.this, Main1.class);
Bundle b = new Bundle();
b.putString("Array",jObject4.toString());
obj_intent.putExtras(b);
Where jObject4 is JSON Object.
Get in next Page :
Intent b = getIntent().getExtras();
String Array=b.getString("Array");
这篇关于从列表视图中的一个活动发送JSON数据到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!