gpt4 book ai didi

java - android发送 Intent 额外

转载 作者:行者123 更新时间:2023-12-02 07:51:37 25 4
gpt4 key购买 nike

应用程序读取 JSON 数据。然后它会将其放入 ListView (正确),但在按下某个项目后,我总是会得到显示的相同值。下面的代码我认为是问题所在,但我找不到。

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);
}
});

最佳答案

更改此:

String fn = ((TextView)findViewById(R.id.course)).getText().toString();

对此:

String fn = ((TextView)view.findViewById(R.id.course)).getText().toString();

关于java - android发送 Intent 额外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10161738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com