Waqas Marwat
Waqas Marwat

Reputation: 17

Android: Button enabled property is not working

i have the String in Edit Text, i want to change change the button state through the string. Please help me out of this problem i am beginner in android. Here is the code.

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);}

Upvotes: 0

Views: 245

Answers (2)

Meenal
Meenal

Reputation: 2877

Change your condition to

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

use this code for making edittext not editable

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

Upvotes: 3

Parvaz Bhaskar
Parvaz Bhaskar

Reputation: 1367

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

Stings are compared by doing ".equals()"

Upvotes: 0

Related Questions