2013-10-31 40 views
0

我在编辑文本中有字符串,我想更改通过字符串更改按钮状态。请帮我解决这个问题,我是Android的初学者。 这是代码。Android:启用按钮的属性不起作用

String Result = jsonResult.toString(); 

JSONObject jsonResponse = new JSONObject(Result); 
int successValue = jsonResponse.getInt("success"); 
String messageValue= jsonResponse.getString("message"); 

String successStringValue = String.valueOf(successValue); 
String messageStringValue = String.valueOf(messageValue); 

t1.setText(messageStringValue); 
String tt1=t1.getText().toString(); 
if (tt1 != "Appointment is ready."){ 
     b1.setEnabled(true);} 
else{ 
     b1.setEnabled(false);} 
+0

它会工作,你的条件是错的 –

+0

如果你w ant要比较字符串,你必须使用'equals()'来比较值而不是引用。你的问题是'=='比较引用,这是行不通的。你需要比较值,所以你必须使用'equals()'方法。 – Sajmon

+0

在if() – Meenal

回答

3

更改条件

if (tt1.equalsIgnoreCase("Appointment is ready.")){ 
    b1.setEnabled(true); 
    } 
    else 
    { 
    b1.setEnabled(false); 
    } 

使用此代码制作的EditText不可编辑

<EditText ... 
    android:clickable="false" 
    android:cursorVisible="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"> 
</EditText> 
+0

中使用tt1.equalsIgnoreCase(“Appointment is ready”)谢谢.....如何使编辑文本字段不可编辑... –

+0

检查此代码是否适用于您 – Meenal

0
if(!(tt1.equals("Some String"))) 
{ 
//enable button 
} 
else 
{ 
//disable it 
} 

蜇被做比较 “.equals()”