2013-07-28 65 views
0

在我的代碼我比較button.gettext與int值都是eqyal但它不打印吐司消息。不是在比較兩個值幫助我....如何比較ibutton文本與整數?

 public static int mDay; 
     Button e01; 

     public static String[][] a = new String[6][7]; 

      e02.setText("" + a[0][2]); 

     if(e01.getText().toString().equals(mDay)) 
    { 
     e01.setTextColor(Color.parseColor("#FFBBFF")); 

    Toast.makeText(this, "Button2 text equals!", Toast.LENGTH_SHORT).show(); 

    } 



      //// in debug mode both gives value 29 
       e01.getText().toString() =29 
       mDay=29 

回答

1

您比較整數用字符串。你需要將INT轉換爲字符串

int a = 29; 
String b = "29"; 
System.out.println(b.equals(a)); 
//prints false 
System.out.println(b.equals(String.valueOf(a))); 
//prints true 

所以基本上你是否應該像這樣:

if(e01.getText().toString().equals(String.valueOf(mDay)) 
1

測試這個條件

Integer.parseInt(e01.getText().toString()) == mDay 
+0

其工作thnxxx – user2619496

0

嘗試 如果(的Integer.parseInt(E01)== MDAY)