gpt4 book ai didi

java - 如何从 xml 解析器获取值到其他类

转载 作者:行者123 更新时间:2023-12-01 05:06:17 25 4
gpt4 key购买 nike

我在互联网上搜索,但没有找到任何可以使用的东西。所以这是我的问题:我有一个在 ListView 中工作的 xml 解析器,但我想将歌曲的 id 提供给其他 Activity ,以便我可以显示它。

最佳答案

1.首先你需要OnItemClickListener()方法ListView

2. 然后,一旦您捕获 index of the row您单击的位置,请使用 Intent()将其传递给另一个 Activity 。

注意:

For this to work, please make the Map as static, and please do map.clear() , everytime before loading the Map with parsed data.

3.当您转到另一个Activity时,希望你的歌曲顺序在Map并在 ListView是一样的,

所以假设您按下 ListView 上的第二项,传递的索引将为1,而在其他Activity只需调用 Map's第一个索引。

注意:

添加 header 将影响 ListView 的索引所以最好使用getItemIdAtPosition(arg)onClick()方法。

例如:

ListView lv = (ListView)findViewById(R.id.MyListView);

lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {

i = new Intent(ProductActivity.this, ProductDetails.class);


i.putExtra("keyAapo", (int) lv.getItemIdAtPosition(arg2));

startActivity(i);

}

});

关于java - 如何从 xml 解析器获取值到其他类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12621419/

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