我在编辑文本中有字符串,我想通过字符串更改按钮状态。请帮我解决这个问题我是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 :(得分: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()”
来比较刺痛