由网友(*空荡的口袋)分享简介:我试图在Android中的HashMap的搜索,但得到的问题:考虑这个例子:的HashMap<字符串,字符串> meMap =新的HashMap<字符串,字符串>();meMap.put(颜色1,红);meMap.put(颜色2,蓝);meMap.put(COLOR3,绿);meMap.put(...
我试图在Android中的HashMap的搜索,但得到的问题:
考虑这个例子:
的HashMap<字符串,字符串> meMap =新的HashMap<字符串,字符串>();
meMap.put(颜色1,红);
meMap.put(颜色2,蓝);
meMap.put(COLOR3,绿);
meMap.put(Color4,白);
现在我想重复,并得到各颜色的值,并希望在显示吐司。 我如何显示呢?
任何想法。
解决方案 迭代器myVeryOwnIterator = meMap.keySet()迭代器()。
而(myVeryOwnIterator.hasNext()){
字符串键=(字符串)myVeryOwnIterator.next();
字符串值=(字符串)meMap.get(密钥);
Toast.makeText(CTX,关键:+键+值:+值,Toast.LENGTH_LONG).show();
}
I have tried to search on HashMap in Android, but getting problem:
Consider this example:
HashMap<String, String> meMap=new HashMap<String, String>();
meMap.put("Color1","Red");
meMap.put("Color2","Blue");
meMap.put("Color3","Green");
meMap.put("Color4","White");
now i want to iterate it and get the value of each colour and want to display in "Toast". how do i display it ?
Any idea.
解决方案Iterator myVeryOwnIterator = meMap.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
String key=(String)myVeryOwnIterator.next();
String value=(String)meMap.get(key);
Toast.makeText(ctx, "Key: "+key+" Value: "+value, Toast.LENGTH_LONG).show();
}
相关推荐
最新文章