public ParseRequest addWhereStartWith(String key, String value) { query.whereStartsWith(key, value); return this; }
/** * Fetch and parse the search results according to the user input. * * @param view */ public void onSearch(View view) { EditText inputName = (EditText) findViewById(R.id.nameInput); EditText inputCourse = (EditText) findViewById(R.id.classInput); String name = inputName.getText().toString(); String course = inputCourse.getText().toString().replaceAll("\\s+", "").toLowerCase(); // Clear listView ListView list = (ListView) findViewById(R.id.search_result_list); list.setAdapter(null); // Reset ordering buttons resetOrderingButtons(); // Setup query final ParseQuery<ParseObject> query = ParseQuery.getQuery("_User"); searchInputCheck = inputChecker(name, course); query.whereEqualTo("available", "yes"); query.orderByAscending("name"); if (searchInputCheck == 0) { Toast.makeText(MainActivity.this, "Empty Search Parameters", Toast.LENGTH_LONG).show(); return; } else if (searchInputCheck == 1) { query.whereStartsWith("name", name); } else if (searchInputCheck == 2) { query.whereEqualTo("courses", course); } else if (searchInputCheck == 3) { query.whereStartsWith("name", name); query.whereEqualTo("courses", course); } else { Toast.makeText(MainActivity.this, "Names only contain standard alphabet", Toast.LENGTH_LONG) .show(); return; } // Fetch list query.findInBackground( new FindCallback<ParseObject>() { public void done(List<ParseObject> parseUsers, ParseException e) { if (e == null) { List<ParseObject> parseUsersList = parseUsers; TextView searchResultTextView = (TextView) findViewById(R.id.searchResultTextView); searchResultTextView.setText( "Search result - " + parseUsers.size() + " tutor(s) found"); if (parseUsers.size() == 0) { if (searchInputCheck == 1) { Toast.makeText( MainActivity.this, "No Results found for tutor name specified.", Toast.LENGTH_LONG) .show(); } else if (searchInputCheck == 2) { Toast.makeText( MainActivity.this, "No Results found for course specified.", Toast.LENGTH_LONG) .show(); } else if (searchInputCheck == 3) { Toast.makeText(MainActivity.this, "No Results found.", Toast.LENGTH_LONG).show(); } } else { List<ParseQuery<ParseObject>> queries = new ArrayList<ParseQuery<ParseObject>>(); for (ParseObject user : parseUsersList) { // Get rating from rating table ParseQuery<ParseObject> query = ParseQuery.getQuery("Ratings"); query.whereEqualTo("username", user.get("username")); queries.add(query); } List<ParseObject> ratings = null; try { ratings = ParseQuery.or(queries).find(); } catch (ParseException p) { Toast.makeText( MainActivity.this, "Problem fetching data from Ratings table" + p, Toast.LENGTH_LONG) .show(); // What is even happening, just die finish(); } usersToRatings = zipLists(parseUsersList, ratings); populateResults((ArrayList) usersToRatings); } } else { // request has failed Toast.makeText(MainActivity.this, "Request failed, try again.", Toast.LENGTH_LONG) .show(); } } }); }