我正在尝试使用 onclicklistener 创建一个列表视图,当用户单击列表视图上的一个项目时,它将启动一个新活动。如何将文件从列表视图传输到另一个活动?下面是我更新 json 数据和更新列表视图的代码
public void updateJSONdata() {
mCommentList = new ArrayList<HashMap<String, String>>();
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(READ_COMMENTS_URL);
try {
mComments = json.getJSONArray(TAG_POSTS);
// looping through all posts according to the json object returned
for (int i = 0; i < mComments.length(); i++) {
JSONObject c = mComments.getJSONObject(i);
// gets the content of each tag
String title = c.getString(TAG_TITLE);
String content = c.getString(TAG_MESSAGE);
String username = c.getString(TAG_LNAME);
String studnum = c.getString(TAG_USERNAME);
// creating new HashMap
/**SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(BsitLoungeActivity.this);
String fname = sp.getString("firstname","anon");
String lname = sp.getString("lasstname","anon");**/
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TITLE, title);
map.put(TAG_MESSAGE, content);
map.put(TAG_LNAME, username);
map.put(TAG_USERNAME, "ID:"+studnum);
// adding HashList to ArrayList
mCommentList.add(map);
// annndddd, our JSON data is up to date same with our array
// listw
}
} catch (JSONException e) {
e.printStackTrace();
}
}
private void updateList() {
ListAdapter adapter = new SimpleAdapter(this, mCommentList,
R.layout.single_post, new String[] { TAG_TITLE, TAG_MESSAGE,
TAG_LNAME,TAG_USERNAME}, new int[] { R.id.title, R.id.message,
R.id.username,R.id.username2 });
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// This method is triggered if an item is click within our
// list. For our example we won't be using this, but
// it is useful to know in real life applications.
}
});
}
我可以使用插入到 hashmap 中的数据吗?如何?请帮助我任何人