另一个屏幕中列表项的详细信息

时间:2012-07-11 13:04:00

标签: android

android解析来自xml :: 的数据 这段代码将数据从xml解析为列表视图我想制作一个详细信息屏幕,当用户点击第一个屏幕中的列表项时,会向用户显示名称的详细信息,任何人都可以帮忙解决这个问题吗?

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class LastActivity extends ListActivity {
    /** Called when the activity is first created. */

    List links;
    List names;
    List uniUrl;
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        Uri uri = Uri.parse((String) uniUrl.get(position));

           Intent intent = new Intent(Intent.ACTION_VIEW, uri);

           startActivity(intent);

    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        links=new ArrayList();
        names=new ArrayList();
        uniUrl=new ArrayList();
        try{
            URL url=new URL(webservice);
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(false);
            XmlPullParser xpp = factory.newPullParser();
            xpp.setInput(getInputStream(url), "UTF_8");
            boolean insideItem = false;




                    // Returns the type of current event: START_TAG, END_TAG, etc..

            int eventType = xpp.getEventType();

            while (eventType != XmlPullParser.END_DOCUMENT) {

                    if (eventType == XmlPullParser.START_TAG) {



                        if (xpp.getName().equalsIgnoreCase("university")) {

                            insideItem = true;

                        } else if (xpp.getName().equalsIgnoreCase("universityName")) {

                            if (insideItem)

                                names.add(xpp.nextText()); //extract the headline

                        } else if (xpp.getName().equalsIgnoreCase("url")) {

                            if (insideItem)

                                links.add(xpp.nextText()); //extract the link of article

                        }
                    }else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){

                        insideItem=false;

                    }



                    eventType = xpp.next(); //move to next element

                }


        }catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (XmlPullParserException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, names);


                setListAdapter(adapter);


    }
    private InputStream getInputStream(URL url) {
        // TODO Auto-generated method stub
        try {
             return url.openConnection().getInputStream();
             } catch (IOException e) {
                   return null;

                 }

1 个答案:

答案 0 :(得分:1)

使用intent.putExtra("your field",your_actual_value);方法,并在要显示详细信息的其他活动中使用getIntent()方法。您想在下一个屏幕中显示哪些具体细节?具体..