Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

search method in ribbit

I'm develop the search method so that you can search users the code it's that one.

    searchText = (EditText)findViewById(R.id.inputSearch);
    searchButton = (Button)findViewById(R.id.Search);
    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String searchedUser = searchText.getText().toString();
            searchedUser = searchedUser.trim();
            if (searchedUser.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EditFriendsActivity.this);
                builder.setMessage(R.string.error_message_search)
                    .setTitle(R.string.signup_error_title)
                    .setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
            }
            else {
                //search for the user!
                setProgressBarIndeterminateVisibility(true);
                //searchedUser.search
                ParseQuery<ParseUser> query = ParseQuery.getQuery(searchedUser);
                query.whereEqualTo("username", searchedUser);
                query.findInBackground(new FindCallback<ParseUser>() {
                    public void done(List<ParseUser> searchList, ParseException e) {
                        if (e == null) {
                            searchedUserList = searchList;

                            String[] usernames = new String[searchedUserList.size()];
                            int i = 0;
                            for(ParseUser user : searchedUserList) {
                                usernames[i] = user.getClassName();
                                i++;
                            }
                            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                                    EditFriendsActivity.this, 
                                    android.R.layout.simple_list_item_checked,
                                    usernames);
                            setListAdapter(adapter);

                            addFriendCheckmarks();
                        } else {
                            Log.d("username", "Error: " + e.getMessage());

                        }
                    }
                });

            }
        }
    });
}

Cant figure out why I continue to see the progress bar and nothing is added to the list

2 Answers

I believe,

.getQuery() is a method belonging to the class ParseUser not ParseQuery. Example:

ParseQuery<ParseUser> query = ParseUser.getQuery(searchedUser);

as indicated here:Parse Documentation

before this if (e == null) { add this

it will make loader disappear after the query is done