解析whereEqualTo

时间:2014-08-11 12:09:27

标签: java android android-layout android-activity parse-platform

我正在尝试从解析中检索信息。特别是,我添加了一个条件,它只返回选择了相同活动的用户列表。

我已经尝试了以下代码,但它似乎确实有效,因为该条件返回一个空列表。

ParseQuery<ParseUser> query = ParseUser.getQuery();
           query.whereNotEqualTo("objectId", currentUserId);
               query.whereEqualTo("ActivityName","");

它基本上会看到哪些用户选择了该特定活动名称并返回

以下是整个代码

 public class MatchingActivity extends Activity {

 private String currentUserId;
    private ArrayAdapter<String> namesArrayAdapter;
    private ArrayList<String> names;
    private ListView usersListView;
    private Button logoutButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.matching);

        logoutButton = (Button) findViewById(R.id.logoutButton);
        logoutButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ParseUser.logOut();
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }
        });

        setConversationsList();
    }

    private void setConversationsList() {
        currentUserId = ParseUser.getCurrentUser().getObjectId();
        names = new ArrayList<String>();


        ParseQuery<ParseUser> query = ParseUser.getQuery();
       query.whereNotEqualTo("objectId", currentUserId);
        query.whereEqualTo("ActivityName",userActivitySelectionName);

        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> userList, ParseException e) {
                if (e == null) {
                    for (int i=0; i<userList.size(); i++) {
                        names.add(userList.get(i).getUsername().toString());
                    }

                    usersListView = (ListView)findViewById(R.id.usersListView);
                    namesArrayAdapter =
                        new ArrayAdapter<String>(getApplicationContext(),
                            R.layout.user_list_item, names);
                    usersListView.setAdapter(namesArrayAdapter);

                    usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> a, View v, int i, long l) {
                            openConversation(names, i);
                        }
                    });

                } else {
                    Toast.makeText(getApplicationContext(),
                        "Error loading user list",
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    public void openConversation(ArrayList<String> names, int pos) {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.whereEqualTo("username", names.get(pos));
        query.findInBackground(new FindCallback<ParseUser>() {
           public void done(List<ParseUser> user, ParseException e) {
               if (e == null) {
                   Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
                   intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
                   startActivity(intent);
               } else {
                   Toast.makeText(getApplicationContext(),
                       "Error finding that user",
                           Toast.LENGTH_SHORT).show();
               }
           }
        });
    }
}

提前致谢。

1 个答案:

答案 0 :(得分:1)

仔细检查数据浏览器,但我猜测该列有&#34;未定义&#34;而不是空字符串。

在这种情况下,您需要使用以下内容:

query.whereDoesNotExist("ActivityName");

whereDoesNotExist()whereExists()函数用于检查列上是否设置了任何值。