好吧,我在這裏有一個開關案例陳述,正在通過嘗試每一個選項。基本上我想要的東西,如果用戶在文本框中輸入字母A的背景將更改爲b!如果他們不輸入字母A,那麼我希望它停止執行代碼。但是,如果用戶輸入的內容發生了變化,例如當背景爲字母A時,例如字母Q,則背景將變爲字母R,而不是告訴用戶他們錯了。基本上我想知道如果我可以阻止更改背景,如果用戶不輸入他們在這裏的字母是代碼。我怎樣才能讓這個更好
public void afterTextChanged(Editable s) {
char ch = words.getText().toString().charAt(0);
switch(ch - 'A') {
case 0:
//A;
gestureViewer.setBackgroundResource(R.drawable.lettersb);
break;
case 1:
gestureViewer.setBackgroundResource(R.drawable.lettersc);
break;
case 2:
gestureViewer.setBackgroundResource(R.drawable.lettersd);
break;
case 3:
gestureViewer.setBackgroundResource(R.drawable.letterse);
break;
case 4:
gestureViewer.setBackgroundResource(R.drawable.lettersf);
break;
case 5:
gestureViewer.setBackgroundResource(R.drawable.lettersg);
break;
case 6:
gestureViewer.setBackgroundResource(R.drawable.lettersh);
break;
case 7:
gestureViewer.setBackgroundResource(R.drawable.lettersi);
break;
case 8:
gestureViewer.setBackgroundResource(R.drawable.lettersj);
break;
case 9:
gestureViewer.setBackgroundResource(R.drawable.lettersk);
break;
case 10:
gestureViewer.setBackgroundResource(R.drawable.lettersl);
break;
case 11:
gestureViewer.setBackgroundResource(R.drawable.lettersm);
break;
case 12:
gestureViewer.setBackgroundResource(R.drawable.lettersn);
break;
case 13:
gestureViewer.setBackgroundResource(R.drawable.letterso);
break;
case 14:
gestureViewer.setBackgroundResource(R.drawable.lettersp);
break;
case 15:
gestureViewer.setBackgroundResource(R.drawable.lettersq);
break;
case 16:
gestureViewer.setBackgroundResource(R.drawable.lettersr);
break;
case 17:
gestureViewer.setBackgroundResource(R.drawable.letterss);
break;
case 19:
gestureViewer.setBackgroundResource(R.drawable.letterst);
break;
case 20:
gestureViewer.setBackgroundResource(R.drawable.lettersu);
break;
case 21:
gestureViewer.setBackgroundResource(R.drawable.lettersv);
break;
case 22:
gestureViewer.setBackgroundResource(R.drawable.lettersw);
break;
case 23:
gestureViewer.setBackgroundResource(R.drawable.lettersx);
break;
case 24:
gestureViewer.setBackgroundResource(R.drawable.lettersy);
break;
case 25:
gestureViewer.setBackgroundResource(R.drawable.lettersz);
break;
如果我將圖片設置爲數組然後從那裏出發,會更好嗎?我用盡包括如果開關的情況下,但它沒有在所有的工作....
我認爲使用數組將是一個好主意。你可能會最終解決你的問題,首先簡化它 – dldnh 2012-03-20 16:35:42
是啊這就是我認爲,我剛剛開始編程不久前,所以即時通訊不是很好陣列哈哈...... – 2012-03-20 16:38:47
保持在它,你會得到那裏 – dldnh 2012-03-20 16:40:23