0

I have fetch data from website and take that data value into hashmap. I also create dynamic linear layout and display ol hashmap value in it. Now problem comes when I want to display hashmap value by name and data type, how can I do that?

for (int i = 0; i < nodes.getLength(); i++)


{


        Element e = (Element) nodes.item(i);
        Node node = nodes.item(i);
        HashMap<String, String> map = new HashMap<String, String>();

        lin = new LinearLayout(this);
        lin.setOrientation(LinearLayout.VERTICAL);
        lin.setBackgroundResource(R.drawable.my_border);

        LinearLayout linbsc = new LinearLayout(this);
        linbsc.setOrientation(LinearLayout.HORIZONTAL);
        map.put("name",node.getAttributes().getNamedItem("name").getNodeValue());
        TextView txtbasicname = new TextView(this);
        txtbasicname.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1f));        
        //txtbasicname.setBackgroundColor(Color.WHITE);
        txtbasicname.setTextColor(Color.WHITE);
        String strbasicname =map.put("name",node.getAttributes().getNamedItem("name").getNodeValue());
        txtbasicname.setText(strbasicname);
        linbsc.addView(txtbasicname);


        lin.addView(linbsc);

        LinearLayout linthrd = new LinearLayout(this);
        linthrd.setOrientation(LinearLayout.HORIZONTAL);

        map.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());
        TextView txtbasicvenuetype = new TextView(this);
        txtbasicvenuetype.setTextColor(Color.WHITE);
        txtbasicvenuetype.setPadding(5, 0, 0, 0);
        String strbasicvenuetype =map.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());
        txtbasicvenuetype.setText(strbasicvenuetype+"-");
        linthrd.addView(txtbasicvenuetype);



        lin.addView(linthrd);

        LinearLayout linforth = new LinearLayout(this);
        linforth.setOrientation(LinearLayout.HORIZONTAL);
        map.put("address",node.getAttributes().getNamedItem("address").getNodeValue());
        TextView txtbasicaddress = new TextView(this);
        txtbasicaddress.setPadding(5, 0, 0, 0);
        txtbasicaddress.setTextColor(Color.WHITE);
        String strbasicaddress =map.put("address",node.getAttributes().getNamedItem("address").getNodeValue());
        txtbasicaddress.setText(strbasicaddress+",");
        linforth.addView(txtbasicaddress);

        map.put("city",node.getAttributes().getNamedItem("city").getNodeValue());
        TextView txtbasiccity = new TextView(this);
        txtbasiccity.setTextColor(Color.WHITE);
        String strbasiccity =map.put("city",node.getAttributes().getNamedItem("city").getNodeValue());
        txtbasiccity.setText(strbasiccity+",");
        linforth.addView(txtbasiccity);


        LinearLayout linfifth = new LinearLayout(this);
        linfifth.setOrientation(LinearLayout.HORIZONTAL);

        map.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());
        TextView txtbasiczip = new TextView(this);
        txtbasiczip.setTextColor(Color.WHITE);
        txtbasiczip.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1f));         
        String strbasiczip =map.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());
        txtbasiczip.setText(strbasiczip+".");
        linfifth.addView(txtbasiczip);  

        lin.addView(linfifth);
        linm.addView(lin);
        dataList.add(map); 
        mylist.add(map);




    }


    System.out.println("data list = "+dataList);
    System.out.println("data list = "+dataListfeture);
1
  • Can you put details about your data which you are storing in HashMap in as key and value. like what is key and what datas are value. Commented Jul 21, 2011 at 6:42

3 Answers 3

1

you can sort an HashMap easily by using a TreeMap as

TreeMap sortedMap1=new TreeMap<String, String>(HashMap Object);

The TreeMap automatically sorts the keys So,we can get a sorted keySet() as follows

sortedMap1.keySet();
Sign up to request clarification or add additional context in comments.

1 Comment

give me some example so i can understands it better way
0

you can use TreeMap is a SortedMap that will sort data on its key.

here is good example take a look.

1 Comment

ye dude nice tutorial but i want some detail so i can manage it better way give me some hints or complete tutorial
0

Declare the HashMap like the following and any item added to the map will be automatically sorted:

// This will create a map that will order the keys, ignoring casing of the strings
// (The 'String.CASE_INSENSITIVE_ORDER' can be removed if not wanted)
TreeMap<String, String> map = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);

That means if you do:

map.put("Hij", "145");
map.put("Abc", "321");
map.put("def", "123");

Then the output would be:

("Abc", "321") ("def", "123") ("Hij", "145")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.