简体   繁体   中英

how to get the value from a xml parser to an other class

I'm searching all over the internet, but I didn't find anything, I could use. So here is my problem: I have an xml parser that works in an list view, but I want to give the id of the song to an other activity , so I can display it.

您可以通过使用setTag()getTag()方法来查看我的答案, 如何从onItemClick访问arrayadapter getView中的变量

1. First you need OnItemClickListener() method for ListView

2. Then once you capture the index of the row on which you clicked, use Intent() to pass it to another activity.

Note:

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

3. When you go to the another Activity , I hope the Order of your Song in Map and in the ListView are same,

So Suppose you pressed the 2nd item on the ListView , the index passed will be 1, and in other Activity just call the Map's 1st index.

Note:

Adding header will effect the index of ListView so its better to use getItemIdAtPosition(arg) in the onClick() method.

Eg:

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

            }

        });

The Intent extra passing option was already said, however, if you are getting to the point where you are passing a bunch of data, you can always make the XML processor reusable and just pass the XML. It's already an encoded format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM