應用程序讀取JSON數據。然後它將它列入清單視圖(正確),但在按下一個項目後,我會始終得到相同的值顯示。在我認爲是問題的代碼下方,但找不到一個。android發送intent額外
try{
JSONArray jArray = new JSONArray(result);
for(int ii=0;ii<jArray.length();ii++){
JSONObject json_data = jArray.getJSONObject(ii);
courseName = json_data.getString("fullname");
HashMap<String,String> map = new HashMap<String, String>();
map.put("fullname", courseName);
myCoursesList.add(map);
}
} catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, myCoursesList,R.layout.my_courses_layout,
new String[] {"fullname"}, new int[] { R.id.course});
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
String fn = ((TextView)findViewById(R.id.course)).getText().toString();
Intent in = new Intent(getApplicationContext(), courseActivity.class);
in.putExtra("fullname", fn);
startActivity(in);
}
});
感謝它的工作(我會在7分鐘內接受答案)也許你可以解釋它有什麼區別? – LTnewbie 2012-04-15 11:52:03
單擊某個項目時,其視圖將返回爲** onItemClick **中的參數,因此您需要使用該視圖執行findViewById以獲取選定行的TextView – waqaslam 2012-04-15 11:53:59