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 Retrieving and Viewing Messages Using Picasso to View Images from the Web

what should i use to show text instead of Images

does Picasso also work to show text instead of Images

2 Answers

Stone Preston
Stone Preston
42,016 Points

to display text just use a simple TextView. thats what that class is for.

public class InboxFragment extends ListFragment {

protected List<ParseObject> mMessages;
private CharSequence displayMessage;




@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);

    return rootView;
}

@Override
public void onResume() {
    super.onResume();

    getActivity().setProgressBarIndeterminateVisibility(true);

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS,ParseUser.getCurrentUser().getObjectId());
query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
query.findInBackground(new FindCallback<ParseObject>() {

    @Override
    public void done(List<ParseObject> messages, ParseException e) {
        getActivity().setProgressBarIndeterminateVisibility(false);

     if (e == null){
         //Success
         mMessages = messages;


            String[] usernames = new String[mMessages.size()];
            int i = 0;
            for (ParseObject message : mMessages){
                usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
                i++;
            }
            if (getListView().getAdapter() == null){
            MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
            setListAdapter (adapter);
     }
            else{
                // refill the adapter
                ((MessageAdapter)getListView().getAdapter()).refill(mMessages);
            }

     }

    }
});

} @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id);

ParseObject message = mMessages.get(position); String messageType = message.getString(ParseConstants.KEY_FILE_TYPE); ParseFile file = message.getParseFile(ParseConstants.KEY_FILE); Uri fileUri = Uri.parse(file.getUrl());

if(messageType.equals(ParseConstants.TYPE_IMAGE)){
    //view Image
    Intent intent = new Intent (getActivity(), ViewImageActivity.class);
    intent.setData(fileUri);
    startActivity(intent);


}else if(messageType.equals(ParseConstants.TYPE_VIDEO)){

    Intent intent = new Intent (Intent.ACTION_VIEW, fileUri);
    intent.setDataAndType(fileUri, "video/*");
    startActivity(intent);

}else if (messageType.equals(ParseConstants.TYPE_TEXT)){


    //Toast.makeText(getActivity(),  displayMessage, Toast.LENGTH_LONG).show();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Message from: " + getString(ParseConstants.KEY_SENDER_NAME) + ".");
    builder.setMessage(displayMessage);
    builder.setPositiveButton("Ok",  new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}
 List<String> ids = message.getList(ParseConstants.KEY_RECIPIENT_IDS);
 if (ids.size() == 1) {
     message.deleteInBackground();

 }
 else{
     ids.remove(ParseUser.getCurrentUser().getObjectId());

     ArrayList<String> idsToRemove = new ArrayList<String>();
     idsToRemove.add(ParseUser.getCurrentUser().getObjectId());


     message.removeAll(ParseConstants.KEY_RECIPIENT_IDS,idsToRemove);
     message.saveInBackground();

 }

}

private String getString(String keySenderName) {
    // TODO Auto-generated method stub
    return null;
}

}

Where should i add the TextView