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 Build a Self-Destructing Message Android App Sending Messages Selecting Recipients

6,862 Points

Recipents Fragment

I tried to do this one in fragment, and everything worked but I am not seeing the Progress Bar, Im sort of confused in where to put that piece of code, As Bens OnCreate method is different from mine.

I tried putting it in my onCreate method, I don't get any errors and also don't see the Progress Bar either :P

I tried to place it OnResume method right after the Super Call, still no use. Any suggestions?

Here is my RecipentsActivity.java file.

package com.dipnsa.dipdip;

import java.util.List;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;

public class RecipentsActivity extends ListActivity {

    public static final String TAG = RecipentsActivity.class.getSimpleName();

    protected List<ParseUser> mFriends;
    protected ParseRelation<ParseUser> mFriendsRelation;
    protected ParseUser mCurrentUser;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_recipents, container,

        return rootView;

    public void onResume() {

        mCurrentUser = ParseUser.getCurrentUser();
        mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);


        ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {

            public void done(List<ParseUser> friends, ParseException e) {

                    if (e == null)  {
                    mFriends = friends;                 
                    String[] usernames = new String[mFriends.size()];
                    int i = 0;
                    for(ParseUser user : mFriends) {
                        usernames[i] = user.getUsername();
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(

                else {
                    Log.e(TAG, e.getMessage());
                    AlertDialog.Builder builder = new AlertDialog.Builder(RecipentsActivity.this);
                        .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();



    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        return super.onOptionsItemSelected(item);


2 Answers

william parrish
william parrish
13,774 Points

Try putting the progress bar visibility line inside mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() { // put it here// @Override .... }

If you think about it, you want the progress indicator to be visible while the above background task is executing, so make it a part of that.

You should try using the Android Studio version to create an Activity with a Fragment, then extend the fragment for a ListFragment and do all the coding in there. It should naturally keep the ActionBar and allow you to use the automated list funcionality android provides.