2015-12-19 87 views
0

方法checkMobileTableAccount用于检查表Account中的电话号码,strMobile是要搜索的电话号码。如何搜索parse.com中的特定值?

public boolean checkMobileTableAccount(final String strMobile) { 
    result = false; 
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Account"); 
    query.findInBackground(new FindCallback<ParseObject>() { 
     @Override 
     public void done(List<ParseObject> objects, ParseException e) { 
      for (ParseObject user : objects) { 
       String mobile = user.getString("phonenumber"); 
       if (strMobile.equals(mobile)) { 
        result = true; 
        break; 
       } 
      } 
     } 
    }); 
    return result; 
} 

如何在循环结束后得到结果?

+0

使云功能和使用'为(用户的parseObject:对象)promises' –

+0

{ 字符串移动= user.getString( “PHONENUMBER”); if(strMobile.equals(mobile)){你可以在这里自己完成这个功能。只有当phonenumber相等时控件才会出现在这里。 休息; } } – Sharath

+0

你不能在查询中添加过滤器吗?您不需要遍历所有用户对象。 –

回答

0

只是不使用方法findInBackground()。使用find(),它不会在后台发出请求。

public boolean checkMobileTableAccount(final String strMobile) { 
     ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Account"); 
     try { 
      List<ParseObject> objects = query.find(); 
      for (ParseObject user : objects) { 
       String mobile = user.getString("phonenumber"); 
       if (strMobile.equals(mobile)) { 
        return true; 
       } 
      } 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 
     return false; 
    }