2013-02-10 78 views
-2

即時有一個很難如何根據其等效信 作爲我的當前代碼顯示的圖像與陣列顯示圖像根據使用散列表

Hashtable<String, Integer> images = new Hashtable<String, Integer>();  
    images.put("A"+"a",R.drawable.a); 
    images.put("B"+"b",R.drawable.b); 
    images.put("C",R.drawable.c); 
    images.put("D",R.drawable.d); 
    images.put("E",R.drawable.e); 
    images.put("F",R.drawable.f); 
    images.put("G",R.drawable.g); 
    images.put("H",R.drawable.h); 
    images.put("I",R.drawable.i); 
    images.put("J",R.drawable.j); 
    images.put("K",R.drawable.k); 
    images.put("L",R.drawable.l); 
    images.put("M",R.drawable.m); 
    images.put("N",R.drawable.n); 
    images.put("O",R.drawable.o); 
    images.put("P",R.drawable.p); 
    images.put("Q",R.drawable.q); 
    images.put("R",R.drawable.r); 
    images.put("S",R.drawable.s); 
    images.put("T",R.drawable.t); 
    images.put("U",R.drawable.u); 
    images.put("V",R.drawable.v); 
    images.put("W",R.drawable.w); 
    images.put("X",R.drawable.x); 
    images.put("Y",R.drawable.y); 
    images.put("Z",R.drawable.z); 

     //String [] search = {"A"+"a","B"+"b"}; <<< this wont work 
     String search = "A"+"a"; 
     if(images.containsKey(search)){ 

      ImageView image = (ImageView)findViewById(R.id.imageView1); 
      image.setImageResource(images.get(search)); 
     } 

如果我手動,只有我做它不會工作它的等效信因此得到「a」或「A」, 如果我輸入字母「b」或「B」,那麼我將使用什麼正確的代碼?
因爲我想如果我繼續這種方法,我想我的代碼將是尷尬

*編輯 我想現在要做的是,該代碼會做一個字符搜索,那麼這個字符將搜索到 res/drawable文件夾到其相應的圖像... 但我的問題是,如何與其他字母搜索... 作爲我上面發佈的代碼...我目前的代碼只適用於「a」或「A」字母

...任何建議都可以改善我的申請

+1

你究竟想要做什麼?請再說明一下 - 目前你的問題是無法回答的。 – Clyde 2013-02-10 23:04:24

+0

作爲先生A - C的回答...我試圖做一個字符搜索 這個字符將搜索res/drawable文件夾到它的等效圖像...但我的問題是,如何搜索與其他字母...作爲我上面發佈的代碼...它只適用於「a」或「A」字母... – 2013-02-10 23:09:19

回答

0

你可以試試:

Collection<String> search = new HashSet<String>{ 
{add("Aa"); 
add("Bb");} 
};  

     if(images.keySet().containsAll(search)){ 
... 
+0

哇哦它的工作原理...感謝您的答覆...我會試驗此代碼和交易與我的問題... – 2013-02-11 00:00:53