2015-07-04 71 views
0

錯誤是'不兼容的類型'(下面評論)。請幫助解決問題。目前使用android studio 1.1.0。任何人都可以幫助解決這裏的錯誤?

public void onClick(View view) {        
      switch (view){ 
       case R.id.ETbutton:        //ERROR: incompatible types 
        String gur = ET.getText().toString();   
        if (gur.contentEquals("left")) { 
         tv.setGravity(Gravity.LEFT);     
        } else if (gur.contentEquals("center")) { 
         tv.setGravity(Gravity.CENTER); 
        } else if (gur.contentEquals("right")) { 
         tv.setGravity(Gravity.RIGHT); 
        } else if (gur.contains("WTF")) { 
         tv.setText("Where's the Fridge?? "); 
         Random rand = new Random(); 
         tv.setTextColor(Color.argb(40, rand.nextInt(265), rand.nextInt(266), rand.nextInt(267))); //Tansparency, and rest colors 
         tv.setTextSize(rand.nextInt(100));      
        } 
        break; 

       case R.id.toggleButton:           //ERROR: incompatible types 
        if(TB.isChecked()){ 
         ET.setInputType(InputType.TYPE_CLASS_TEXT);         
        }else{ 
         ET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); 
        } 
        break; 
      } 
     } 
+0

R.id.ETbutton應該是類型視圖的 – Madhan

回答

0

switch()期望一個整數。你通過它查看

switch (view) // WRONG: switch doesn't want a View 

必須是

switch(view.getId()) // CORRECT: The View id is an integer 
相關問題