-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」を入力すると、今度はどの適切なコードを使用しますか?
その方法を続けると、コードがぎこちなくなると思うので

*編集したいのは、このコードが1文字の検索を行い、次にこの文字がres/drawableフォルダーを検索して同等の画像にすることです...しかし、私の問題は、他の文字で検索する方法です。 ..上記のコードとして...私の現在のコードは「a」または「A」の文字でのみ機能します

...アプリケーションを改善するための提案は何でも構いません

4

1 に答える 1

0

あなたが試すことができます:

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

        if(images.keySet().containsAll(search)){
...
于 2013-02-10T23:42:53.977 に答える