2016-12-26 66 views
-1

请我需要你的帮助 我在Android上构建这个应用程序,我遇到了这个问题,其中一个字符串数据从Firebase数据库中检索并分配给一个字符串值,当我尝试使用(IF)语句来使用内部条件,我所得到的只是编译器检查值条件并从不输入语句。 我使用调试模式检查正在运行的应用程序,存储到字符串中的值是否正确,以及Statement是否在其中没有问题。Android如果语句没有被某些原因访问

我加入了代码的一部分,我有问题

myRef.addValueEventListener(new ValueEventListener() { 
     public static final String TAG = "Testtttttttt"; 

     @Override 
     public void onDataChange(DataSnapshot dataSnapshot) { 
      // This method is called once with the initial value and again 
      // whenever data at this location is updated. 
      String value = dataSnapshot.getValue(String.class); 
      Log.d(TAG, "Value is: " + value); 
      if (value == "START") { 
       textView.setText(value); 


      } 
     } 
+0

使用value.equals( “开始”),而不是价值== “START” –

+0

请遵循通常被贴在其他之中的甲骨文的Java网页上的标准。字符串比较应该总是使用stringVar.equals()方法 – Manny265

回答

1

你应该使用:

myRef.addValueEventListener(new ValueEventListener() { 
    public static final String TAG = "Testtttttttt"; 

    @Override 
    public void onDataChange(DataSnapshot dataSnapshot) { 
     // This method is called once with the initial value and again 
     // whenever data at this location is updated. 
     String value = dataSnapshot.getValue(String.class); 
     Log.d(TAG, "Value is: " + value); 
     // correct compare string1.equals(string2) 
     if (value.equals("START")) { // You cant compare string1 == string2 
      textView.setText(value); 


     } 
    }