display Hashmap return values one at a time random
<p>I'm trying to display one item at a time randomly inside a textview. I can display all of them with the below code.         </p>

<pre><code>final HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
    NodeList nodes = doc.getElementsByTagName("item");
   // for (int i = 0; i &lt; nodes.getLength(); i++) {
        // creating new HashMap


    for (int i = 0; i &lt; nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        map.put(KEY_TITLE,parser.getValue(element, KEY_TITLE));



        menuItems.add(map);

        List&lt;String&gt; valuesList = new ArrayList&lt;String&gt;(map.values()); 
        int randomIndex = new Random().nextInt(valuesList.size()); 
       randomValue = valuesList.get(randomIndex); 
       Log.i("inside", randomValue);    
    }

     Collections.shuffle(menuItems);
     menuItems.add(map);
        next.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
             Log.i("outide",map.get(KEY_TITLE));    
                 myImage.setImageResource(imageArr[rgenerator.nextInt(imageArr.length)]);
            }
     });




 }
 }
</code></pre>

<p>Can any body tell me what's the easiest way to display the data randomly?</p>

<p>Thanks,</p>

<p>Hi Guys,</p>

<p>This is what I came up with which seems to work like I want it to.</p>

<pre><code>final ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();

    XMLParser parser = new XMLParser();
    Document doc = parser.getDomElement(responseBody);
     NodeList nodes = doc.getElementsByTagName("item");

     for (int i = 0; i &lt; nodes.getLength(); i++) {
            // creating new HashMap
       // for (int i = 0; i &lt; nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
            map.put(KEY_TITLE,parser.getValue(element, KEY_TITLE));


            menuItems.add(map);
          }


     Collections.shuffle(menuItems);
     Map&lt;String, String&gt; myValueMap = menuItems.get(0); 
     textView.setText(myValueMap.get(KEY_TITLE));
                next.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                     Collections.shuffle(menuItems);
                     Map&lt;String, String&gt; MapBtn = menuItems.get(0);
                       textView.setText(MapBtn.get(KEY_TITLE));
                        myImage.setImageResource(imageArr[rgenerator.nextInt(imageArr.length)]);
            }
         });

 }
 }
</code></pre>
