Simon Ho
Simon Ho

Reputation: 598

How to populate a listview from excel-exported xml?

Previously, I only know using the following "add" method to add item to listview row by row using arrayadapter:

    private ArrayList<pregnancyItem> generateData() {
        ArrayList<pregnancyItem> items = new ArrayList<pregnancyItem>();

        items.add(new pregnancyItem("ACARBOSE", "GLUCOBAY", "B", "B3", "Probably compatible", "unknown/not recommended"));
        items.add(new pregnancyItem("ACARBOSE", "GLUCOBAY", "B", "B3", "Probably compatible", "unknown/not recommended"));

        return items;
    }

Now the problem comes as there will be 1000 row in the list. I already learnt to export the excel as XML data like the following format:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
        <GenericName>Acarbose</GenericName>
        <BrandName>Glucobay</BrandName>
        <FDA>B</FDA>
        <AUS>B3</AUS>
        <Briggs>Probably compatible</Briggs>
        <Lexicomp>Excretion in breast milk unknown/not recommended</Lexicomp>
    </record>
    <record>
        <GenericName>Acarbose</GenericName>
        <BrandName>Glucobay</BrandName>
        <FDA>B</FDA>
        <AUS>B3</AUS>
        <Briggs>Probably compatible</Briggs>
        <Lexicomp>Excretion in breast milk unknown/not recommended</Lexicomp>
    </record>
</data-set>

Is there a way to populate a listview in a smarter way using this format?

Upvotes: 0

Views: 584

Answers (1)

Harsh Sharma
Harsh Sharma

Reputation: 898

You can do this thing by using XMLPullParser.

Check These tutorial.This will definitely Help You. This tutorials are simlar to your problem.

  1. http://theopentutorials.com/post/uncategorized/android-simple-xmlpullparser-tutorial/

  2. http://wptrafficanalyzer.in/blog/android-xml-parsing-with-xmlpullparser-and-loading-to-listview-example/

Upvotes: 1

Related Questions