我在编辑文本中有字符串,我想更改通过字符串更改按钮状态。请帮我解决这个问题,我是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);}
它会工作,你的条件是错的 –
如果你w ant要比较字符串,你必须使用'equals()'来比较值而不是引用。你的问题是'=='比较引用,这是行不通的。你需要比较值,所以你必须使用'equals()'方法。 – Sajmon
在if() – Meenal