简体   繁体   English

高效读取大量数据

[英]Efficiently Reading in a lot of Data

I am currently working on a newspaper app that is supposed to read articles that are currently docx (I can change format). 我目前正在使用报纸应用程序,该应用程序应阅读当前为docx的文章(我可以更改格式)。 I was wondering what is the best way to reference them to my app so that they can be called with a button press. 我想知道什么是将它们引用到我的应用程序的最佳方法,以便可以通过按下按钮来调用它们。 I'm aware that I can set a separate layout and activity for each article but I have around two hundred articles so that isn't very practical. 我知道我可以为每篇文章设置单独的布局和活动,但是我大约有200篇文章,因此不太实用。 Here is my custom list view I would like to put articles here as well as in each of my sections. 这是我的自定义列表视图,我想在这里以及每个部分中都发表文章。

package com.tjo.gmagnaum;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.HashMap;


public class CustomizedListView extends Fragment {  // All static variables
    static final String URL = "http://gmag.hossti.com";
    // XML node keys
    static final String KEY_SONG = "song"; // parent node
    static final String KEY_ID = "id";
    static final String KEY_TITLE = "title";
    static final String KEY_ARTIST = "artist";
    static final String KEY_DURATION = "duration";
    static final String KEY_THUMB_URL = "thumb_url";

    ListView list;
    LazyAdapter adapter;
    ArrayList<HashMap<String, String>> songsList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.news, container, false);
       songsList = new ArrayList<HashMap<String, String>>();

    list=(ListView)  rootView.findViewById(R.id.list);

        new RetrieveXML().execute(URL);

        // Getting adapter by passing xml data ArrayList


        // Click event for single list row                XMLParser parser = new XMLParser();

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
            }
        });
        return rootView;
    }

    class RetrieveXML extends AsyncTask<String, Void, String> {

        private Exception exception;
        XMLParser parser = new XMLParser();

        protected String doInBackground(String... urls) {
            try {

                return parser.getXmlFromUrl(urls[0]);
            } catch (Exception e) {
                this.exception = e;
                return null;
            }
        }

        protected void onPostExecute(String xml) {
            Document doc = parser.getDomElement(xml); // getting DOM element

            NodeList nl = doc.getElementsByTagName(KEY_SONG);
            // looping through all song nodes <song>
            for (int i = 0; i < nl.getLength(); i++) {
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) nl.item(i);
                // adding each child node to HashMap key => value
                map.put(KEY_ID, parser.getValue(e, KEY_ID));
                map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
                map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
                map.put(KEY_THUMB_URL, parser.getValue(e, KEY_ID));
                map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

                // adding HashList to ArrayList
                songsList.add(map);

            }

            adapter=new LazyAdapter(getActivity(), songsList);

            list.setAdapter(adapter);
        }
    }
}

If anyone really cares you can set up a simple domain name (tons of free ones available) and in the control panel of your hosting there should be an FTP file manager where you can add and organize files with a pretty simple url look up perfect for code. 如果有人真的很在意您可以设置一个简单的域名(大量可用的免费域名),并且在主机的控制面板中应该有一个FTP文件管理器,您可以在其中添加和组织带有一个非常简单的url的文件,查找非常适合码。 This is what I used hope it helps you guys! 这就是我曾经希望对您有帮助的东西!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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