我需要通過行點擊前轉移從JSON實體解析的id的值(列表視圖中的第一個項目的ID爲861(這是從JSON獲得)第二個823 ,我需要正確的ID傳送到FrafmentB不能得到正確的ID進入片段
這是我應得的ID
List<NameValuePair> param = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.makeHttpRequest(URL_MESSAGES, "GET", param, token);
JSONObject data = json.getJSONObject("data");
JSONArray messages = data.getJSONArray("messages");
for(int i=0;i<messages.length();i++){
JSONObject c = messages.getJSONObject(i);
read_status=c.getString(TAG_READ_STATUS);
if(read_status.equals("unread")){
msgID=c.getInt("id");
Log.d("BUNDLE ID", String.valueOf(msgID));
title = c.getString(TAG_TITLE);
Log.d("TITLE",title);
time=c.getString(TAG_TIME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TITLE, title);
map.put(TAG_TIME, time);
mailList.add(map);
這樣,我的ID轉移到片段
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FragmentManager fm=getFragmentManager();
FragmentTransaction transaction=fm.beginTransaction();
bundle.putInt("message", msgID);
MessageView ViewMessages=new MessageView();
ViewMessages.setArguments(bundle);
transaction.replace(R.id.fragmentInnerMail,ViewMessages);
transaction.commit();
}
用戶點擊時從行中的項目,只有最後一個ID(至極通過的AsyncTask解析)進入fragmentB,不是基於從列表視圖行的國際直撥電話,我不出來,請大家幫忙
適配器
@Override
protected void onPostExecute(String s) {
ListView list = (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter = new SimpleAdapter(
getActivity(), mailList,
R.layout.mail_row, new String[] { TAG_TITLE,
TAG_TIME}, new int[] {
R.id.mTitle,R.id.mDate});
list.setAdapter(adapter);
pDialog.dismiss();
}
你使用'SimpleAdapter'以郵件列表作爲數據集? – Blackbelt 2014-10-10 07:25:50
是的,我貼了適配器 – Alex 2014-10-10 07:36:20