【发布时间】:2015-04-06 21:58:28
【问题描述】:
需要在我的代码中进行一些更正,我正在尝试使用意图将三个字符串从列表项传递到下一个活动。一切正常,但问题是我不知道如何获取列表项的确切位置,因此我只能选择该列表项的内容并将它们带到我的其他活动中。
ActivityOne.java
int ctryId;
mCommentList = new ArrayList<HashMap<String, String>>();
try {
mComments = json.getJSONArray(TAG_POSTS);
for (int i=mComments.length() - 1; i>=0; i--) {
JSONObject c = mComments.getJSONObject(i);
ctryId = c.getInt(TAG_COUNTRY_ID);
if (ctryId == 2){
ListItem item = new ListItem();
item.setRegionId(c.getString(TAG_REGION_ID));
item.setRegionName(c.getString(TAG_REGION_NAME));
item.setCountryId(c.getString(TAG_COUNTRY_ID));
listItems.add(item);
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Intent intent = new Intent(RegionsOfVisit.this, LocationsActivity.class);
intent.putExtra("Regions_of_visit_region_id", item.getRegionId());
intent.putExtra("Regions_of_visit_region_name", item.getRegionName());
intent.putExtra("Regions_of_visit_country_id", item.getCountryId());
startActivity(intent);
}
});
}
// notify data changes to list adapater
regionsOfVisitListAdapter.notifyDataSetChanged();
任何建议都将受到高度赞赏
【问题讨论】:
-
item.getRegionId()。在这里可以访问吗?你能编译这行没有错误吗?
-
Amsheer,我可以编译没有错误
标签: android