Android:启用按钮的属性不起作用

时间:2013-10-31 11:35:42

标签: 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);}

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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

通过“.equals()”

来比较刺痛
相关问题