1. Check out our companion app, Forums for Android! Download from Google Play

xml parsing listview in android like category,subcategory

Discussion in 'Application Development' started by krishnaveni, Dec 26, 2012.

  1. krishnaveni

    krishnaveni Well-Known Member
    Thread Starter
    55

    Dec 16, 2011
    158
    0
    55
    chennai
    i have to develop android listview using xml parsing., This is my xml feed:http://dev.mercuryminds.com/xctesting/feed.xml

    Am getting xml feed from my mysql server.

    The product is added day to day.so how can i develop these.

    Here i need 3 kind of listview:

    1st view: Category
    2nd view: SubCategory
    3rd view: Product

    In 1st view have to display Categoryname alone.


    In 2nd view:

    have to display subcategoryname belongs to Categoryname.

    In 3nd View:

    Have to display Product name and price belongs to subcategoryname.

    This is my 1st view code:
    [HIGH]

    public class MainActivity extends Activity {
    static final String URL = "http://dev.mercuryminds.com/xctesting/feed.xml";

    static String KEY_CATEGORY = "Category";
    static final String KEY_TITLE = "Categoryname";

    ListView lview3;
    LazyAdapter adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);

    // looping through all song nodes &lt;song&gt;
    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);


    map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));

    songsList.add(map);
    }
    lview3 = (ListView) findViewById(R.id.listView1);
    adapter = new LazyAdapter(this, songsList);
    lview3.setAdapter(adapter);

    lview3.setOnItemClickListener(new OnItemClickListener() {

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

    });

    }

    }
    [/HIGH]

    How can i develop 2nd view and 3rd view.please give me solution for me..
     

    Advertisement

Share This Page

Loading...