Android studio 在RSS提要标记中显示数据

Android studio 在RSS提要标记中显示数据,android-studio,xml-parsing,display,Android Studio,Xml Parsing,Display,我试图只显示描述标记中的位置和大小 起始日期/时间:2021年1月18日星期一07:41:02;地点: 洛沙林,高地;横向/纵向:56.552,-5.815;深度:8公里;震级: 1.9 我正在解析URL中的数据并对其进行解析。这是到目前为止我所拥有的代码,它显示了从标记开始的所有内容: public class MainActivity extends AppCompatActivity { ListView lvRss; ArrayList mLink;

我试图只显示描述标记中的位置和大小

起始日期/时间:2021年1月18日星期一07:41:02;地点: 洛沙林,高地;横向/纵向:56.552,-5.815;深度:8公里;震级: 1.9

我正在解析URL中的数据并对其进行解析。这是到目前为止我所拥有的代码,它显示了从标记开始的所有内容:

public class MainActivity extends AppCompatActivity {

        ListView lvRss;
        ArrayList mLink;
        ArrayList mTitle;
        ArrayList mGeolat;
        ArrayList mGeolong;
        ArrayList mDescription;
        ArrayList mPubdate;
        ArrayList mCategory;
        ArrayList mLocation;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            lvRss = (ListView) findViewById(R.id.lvRss);

            mTitle = new ArrayList();
            mDescription = new ArrayList();
            mLink = new ArrayList();
            mGeolat = new ArrayList();
            mGeolong = new ArrayList();
            mPubdate = new ArrayList();
            mCategory = new ArrayList();
            mLocation = new ArrayList();


            lvRss.setOnItemClickListener(new AdapterView.OnItemClickListener() {
               @Override
               public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    // TODO: Process clicked item here
                   Uri uri = Uri.parse((mLink.get(position)).toString());
                   Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                   startActivity(intent);
               }
          });

            new ProcessBackground().execute();
        }

        public InputStream getInputStream(URL url) {
            try {
                return url.openConnection().getInputStream();
            } catch (IOException e) {
                return null;
            }
        }

        public class ProcessBackground extends AsyncTask<Object, Void, Exception> {

            Exception exception = null;

            @Override
            protected Exception doInBackground(Object[] params) {

                try {
                    URL url = new URL("http://quakes.bgs.ac.uk/feeds/MhSeismology.xml");
                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(false);
                    XmlPullParser xpp = factory.newPullParser();
                    xpp.setInput(getInputStream(url), "UTF_8");
                    boolean insideItem = false;
                    int eventType = xpp.getEventType();
                    while (eventType != XmlPullParser.END_DOCUMENT) {
                        if (eventType == XmlPullParser.START_TAG) {
                            if (xpp.getName().equalsIgnoreCase("item")) {
                                insideItem = true;
                            } else if (xpp.getName().equalsIgnoreCase("title")) {
                                if (insideItem) {
                                    mTitle.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("description")) {
                                if (insideItem) {
                                    mDescription.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("link")) {
                                if (insideItem) {
                                    mLink.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("pubdate")) {
                                if (insideItem) {
                                    mPubdate.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("category")) {
                                if (insideItem) {
                                    mCategory.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("geo:lat")) {
                                if (insideItem) {
                                    mGeolat.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("geo:long")) {
                                if (insideItem) {
                                    mGeolong.add(xpp.nextText());
                                }
                            } else if (xpp.getName().equalsIgnoreCase("description")) {
                                if (insideItem) {
                                    mLocation.add(xpp.nextText());
                                }
                            }
                        } else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")) {
                            insideItem = false;
                        }
                        eventType = xpp.next();
                    }
                } catch (MalformedURLException e) {
                    exception = e;
                } catch (IOException e) {
                    exception = e;
                } catch (XmlPullParserException e) {
                    exception = e;
                }
                return exception;
            }

            @Override
            protected void onPostExecute(Exception s) {
                super.onPostExecute(s);

                ArrayAdapter adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, mDescription);
                lvRss.setAdapter(adapter);

            }
        }
    }

public类MainActivity扩展了AppCompatActivity{
列表视图lvRss;
ArrayList mLink;
ArrayList mTitle;
ArrayList mGeolat;
ArrayList mGeolong;
阵列列表描述;
ArrayList数据库;
ArrayList-mCategory;
阵列位置;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvRss=(ListView)findViewById(R.id.lvRss);
mTitle=newarraylist();
mddescription=new ArrayList();
mLink=newarraylist();
mGeolat=newarraylist();
mGeolong=newarraylist();
mPubdate=newarraylist();
mCategory=newarraylist();
mLocation=newarraylist();
lvRss.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//TODO:在此处处理单击的项目
Uri=Uri.parse((mLink.get(position)).toString());
意图=新意图(Intent.ACTION\u视图,uri);
星触觉(意向);
}
});
新建ProcessBackground().execute();
}
公共输入流getInputStream(URL){
试一试{
返回url.openConnection().getInputStream();
}捕获(IOE异常){
返回null;
}
}
公共类ProcessBackground扩展异步任务{
异常=空;
@凌驾
受保护的异常doInBackground(对象[]参数){
试一试{
URL=新URL(“http://quakes.bgs.ac.uk/feeds/MhSeismology.xml");
XmlPullParserFactory工厂=XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp=factory.newPullParser();
setInput(getInputStream(url),“UTF_8”);
布尔值insideItem=false;
int eventType=xpp.getEventType();
while(eventType!=XmlPullParser.END_文档){
if(eventType==XmlPullParser.START_标记){
if(xpp.getName().equalsIgnoreCase(“项”)){
insideItem=真;
}else if(xpp.getName().equalsIgnoreCase(“title”)){
如果(内部项目){
添加(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“说明”)){
如果(内部项目){
mddescription.add(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“链接”)){
如果(内部项目){
mLink.add(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“pubdate”)){
如果(内部项目){
mPubdate.add(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“类别”)){
如果(内部项目){
添加(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“geo:lat”)){
如果(内部项目){
mGeolat.add(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“geo:long”)){
如果(内部项目){
mGeolong.add(xpp.nextText());
}
}else if(xpp.getName().equalsIgnoreCase(“说明”)){
如果(内部项目){
添加(xpp.nextText());
}
}
}else if(eventType==XmlPullParser.END_标记&&xpp.getName().equalsIgnoreCase(“项”)){
insideItem=假;
}
eventType=xpp.next();
}
}捕获(格式错误){
例外=e;
}捕获(IOE异常){
例外=e;
}catch(XMLPullParseRexE){
例外=e;
}
返回异常;
}
@凌驾
受保护的void onPostExecute(异常s){
super.onPostExecute(s);
ArrayAdapter=新的ArrayAdapter(MainActivity.this,android.R.layout.simple\u list\u item\u 1,MDDescription);
设置适配器(适配器);
}
}
}