哈希表到getkey

时间:2013-07-08 12:04:17

标签: android

嘿伙计们我想把hashtable的密钥放在edittext中,然后在textview中显示我的值

Hashtable<String, Integer> ht=new Hashtable<String, Integer>();
//Enumeration<String> enm; 
ht.put("rakan", 100);
ht.put("ahmad", 200);
ht.put("moh", 3000);


Iterator<String> myVeryOwnIterator = ht.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
    String key=(String)myVeryOwnIterator.next();
    Integer value=(Integer)ht.get(key);
    Toast.makeText(getBaseContext(), "Key: "+key+" Value: "+value , Toast.LENGTH_LONG).show();
}


//(TextView)findViewById(R.id.tvShowValue).setTex(Integer.valueOf(+key));

//enm=ht.keys();
int id= Integer.parseInt(((EditText)findViewById(R.id.etPutKey)).getText().toString());
((TextView)findViewById(R.id.tvShowValue)).setText(Integer.valueOf(id));

1 个答案:

答案 0 :(得分:1)

String key = ((EditText)findViewById(R.id.etPutKey)).getText().toString());
((TextView)findViewById(R.id.tvShowValue)).setText(String.valueOf(ht.get(key)));