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 Relating Users in Parse.com Executing a Query

Extra credit:Displaying additional Fields: Ribbit Android App

Has anyone managed to display additional fields in the friends profile activity.

I can display once one Field at a time,How do make all the fields appear in the list..??? or i do not a need a array adapter..? Please help!

9 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Can you paste in the code you are trying? The intent with this extra credit challenge is to create a new Activity that shows details about a selected user. There are lots of ways to tackle this, but here's one: Tapping on the user should send that user's ID or the ParseUser object representing that user to the profile Activity as an "extra" on the Intent. Then you could use that information to fill in TextViews on the new Activity with the details about that user.

Thanx for your response. How can I use a text view.? As I'm received data from parse as a list.?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

It's a bit of a complex challenge. If you create a brand new Activity that displays user information, you could add TextViews to display things like their username and email address. Step 1 in the Extra Credit is to add additional fields to the signup page. Have you done that?

  1. Add some additional optional fields to the Sign Up screen. Maybe things like:
  • First name
  • Last name
  • Hometown
  • Website

Yes I have done that, I have added two extra fields. Gender Country So when I tap on the user name it takes me to a new activity which I created called friends profile, but I can only display one field at a time because of the array adapter! Should I create a simple adapter.? Or a custom adapter.?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Okay, thanks for the details...I understand better where you are now. Can you paste in the code for your new Profile Activity? It sounds like you might have a ListView in there, but with only a few pieces of information to display, why don't you make it a regular Activity that has a few different TextViews? Then you could set each TextView manually from the ParseUser object instead of using an adapter. Only one ParseUser should be passed to the Profile Activity, not a whole list of them.

package com.grape.messagegram;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseFacebookUtils.Permissions.User;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

public class FriendsProfileActivity extends Activity {
    public static final String TAG = FriendsProfileActivity.class.getSimpleName();

    protected EditText mUsers;





    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.orderByAscending(ParseConstants.KEY_USERNAME);
        query.setLimit(1000);
        query.findInBackground(new FindCallback<ParseUser>() {

            @Override
            public void done(List<ParseUser> users, com.parse.ParseException e) {
                setProgressBarIndeterminateVisibility(false);
        // TODO Auto-generated method stub





                if (e == null){
                    //Success


                    final EditText edittext = (EditText) findViewById(R.id.EmailProfileField);
                    TextView mText = (TextView) findViewById(R.id.EmailProfileField);
                    String storedData = ((ParseUser) users).getUsername();
                    mText.setText(storedData);

                }


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

                }
                // TODO Auto-generated method stub

            }
        });
    }









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





    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.friends_profile, menu);
        return true;
    }

}
Ben Jakuben
Ben Jakuben
Treehouse Teacher

So this code is giving you a list of 1000 users just like the EditFriendsActivity. How do you get to this FriendsProfileActivity? The intent of this challenge is to select one user from one of the other lists using the onListItemClick() method of a ListView. Then you could access that one user in here and display the details of the user that was tapped on.

If you want to simply verify that this Activity is working like you planned, you could simply get the first user in the list in your done() method:

ParseUser user = users.get(0);

There is my code, parse is giving me a list of the data is there a way to get one single string from the stored data on parse.com..?

When i try the above code i get the following error

05-13 21:31:35.198: E/AndroidRuntime(965): java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.parse.ParseUser

Yes Iam able to reach this activity by tapping on the user. But i do not want a list of users,I want the extra infromation stored on parse.com about each user,for eg i created two extra fields on the sign up page called 'gender' and 'country'. The above code is only for showing the extra fileds.My problem is that Iam getting the parse user data as a list,due to which I am unable to display it in a text view. Or Iam doing some other mistake..??? I found this egxample online would this work..?

Would it work..?

            ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
            String objectIduser = gameScore.getObjectId();
            query.getInBackground("objectIduser", new GetCallback<ParseObject>() {
            String usergender = gameScore.getString("gender") 
            @Override
            public void done(ParseObject objectprofile, ParseException e) {
            if (e == null) {
             // object will be your game score
             } else {
             // something went wrong
                      }
                             }
                  });



final EditText edittext = (EditText) findViewById(R.id.EmailProfileField);
                TextView mText = (TextView) findViewById(R.id.EmailProfileField);

                mText.setText(objectprofile);
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Let's start with something very basic. From the list you currently have, you can select the very first user with this line of code from my previous comment:

ParseUser user = users.get(0);

Set this user variable in your done() method before you try setting the EditText and TextView. Then you can use the user variable to get that other information.

If this example works, then we can talk about using a single user instead of a list.

Yes this method works I am able to get the username and all the other fields. Thank you very much for your help. Can you please tell me how to get the name that Is tapped on in the editfriendactivity and use that name in the friendsprofileactivity to get fields only of the person who's name is tapped on I know I can use "whereequalto" method in the parse query. But how do I get the name.?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

You're on the right track! In onListItemClick() of EditFriendsActivity, you can tell which item was clicked on using the parameters of that method. You can use the position parameter to get the corresponding user with mUsers.get(position), and from that ParseUser you could get the name.

Ok,Thanks! Ohk yeah i can d that. and then can i transfer the value i get using the method shown in the blog reader app to open web page within the app.?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Yes, that should work! If you have trouble with it let me know in a new post (tag me to make sure I see it).

It's working. Thank you so much for your help! Treehouse is amazing!!!!