列表项的另一个画面中的细节

列表项的另一个画面中的细节

本文介绍了列表项的另一个画面中的细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

机器人解析从XML数据:: 这code解析从XML数据到一个列表视图我想让它显示用户名的详细信息时,点击进入列表项的第一个屏幕上任何一个可以帮助解决这个??

 进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.net.MalformedURLException;
进口的java.net.URL;
进口的java.util.ArrayList;
进口的java.util.List;

进口org.xmlpull.v1.XmlPullParser;
进口org.xmlpull.v1.XmlPullParserException;
进口org.xmlpull.v1.XmlPullParserFactory;

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

公共类LastActivity扩展ListActivity {
    / **第一次创建活动时调用。 * /

    单链接;
    列表名称;
    名单uniUrl;
    @覆盖
    保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
        // TODO自动生成方法存根
        super.onListItemClick(L,V,位置ID);
        开放的我们的uri = Uri.parse((字符串)uniUrl.get(位置));

           意向意图=新的意图(Intent.ACTION_VIEW,URI);

           startActivity(意向);

    }
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        链接=新的ArrayList();
        名称=新的ArrayList();
        uniUrl =新的ArrayList();
        尝试{
            网址URL =新的URL(Web服务);
            XmlPullParserFactory工厂= XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(假);
            XmlPullParser XPP = factory.newPullParser();
            xpp.setInput(的getInputStream(URL),UTF_8);
            布尔insideItem = FALSE;




                    //返回当前事件的类型:START_TAG,END_TAG等。

            INT EVENTTYPE = xpp.getEventType();

            而(EVENTTYPE!= XmlPullParser.END_DOCUMENT){

                    如果(EVENTTYPE == XmlPullParser.START_TAG){



                        如果(xpp.getName()。equalsIgnoreCase(大学)){

                            insideItem = TRUE;

                        }否则,如果(xpp.getName()。equalsIgnoreCase(universityName)){

                            如果(insideItem)

                                names.add(xpp.nextText()); //提取标题

                        }否则如果(xpp.getName()。equalsIgnoreCase(URL)){

                            如果(insideItem)

                                links.add(xpp.nextText()); //提取制品的链路

                        }
                    }否则,如果(EVENTTYPE == XmlPullParser.END_TAG和放大器;&安培; xpp.getName()equalsIgnoreCase(项目)){

                        insideItem = FALSE;

                    }



                    EVENTTYPE = xpp.next(); //移动到下一个元素

                }


        }赶上(MalformedURLException异常E){

            e.printStackTrace();

        }赶上(XmlPullParserException E){

            e.printStackTrace();

        }赶上(IOException异常E){

            e.printStackTrace();

        }
        ArrayAdapter适配器=新的ArrayAdapter(这一点,android.R.layout.simple_list_item_1,姓名);


                setListAdapter(适配器);


    }
    私人的InputStream的getInputStream(网址URL){
        // TODO自动生成方法存根
        尝试 {
             返回url.openConnection()的getInputStream()。
             }赶上(IOException异常E){
                   返回null;

                 }
 

解决方案

使用 intent.putExtra(你的领域,your_actual_value); 的方法,并使用 getIntent()其他活动方法,其中要显示的详细信息。你想要什么具体的细节在接下来的屏幕上显示?要具体。

android parsing data from xml::this code parse a data from xml to a list view i want to make a detail screen which show the user the detail of names when it clicked into the list item in first screen any one can help with this??

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;

                 }
解决方案

Use intent.putExtra("your field",your_actual_value); method and use getIntent() method in other activity in which you want to display details. What specific details you want to display in the next screen? Be specific..

这篇关于列表项的另一个画面中的细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:29