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 Adding a Send Button

Extending ActionBarActivity and ListView? android studio 1.0

It seems like not extending ActionBarActivity will not implement the action bar but if I extend ActionBar I lose some of the functionality of listView.

How can i implement both?

9 Answers

Harry James
Harry James
14,780 Points

Hey Alejandro!

Sorry, I was a bit confused and thought you were extending just ActionBar.

I managed to reproduce this on my side and fixed it by setting the theme in AndroidManifest.xml like this:

android:theme="@android:style/Theme.Holo.Light.DarkActionBar" >

Hope it helps! :)

Harry James
Harry James
14,780 Points

That'd odd. I'm extending ActionBarActivity and am able to see the Action Bar.

In your AndroidManifest.xml file, are you using a specific theme?

Check the

android:theme="@style/AppTheme"

attribute and see if it is AppTheme or not.

If that doesn't fix it, I recommend you try using SDK 21 and seeing if you can reproduce this.

If even after that you are reproducing the issue, you can always write a class extending ActionBarActivity inside of the class extending ActionBar but, this may be a bit of a confusing technique for starting off.


If nothing above fixed your problem, you could wait to see if someone else knows how to resolve this or, if you would like, I could see if I could reproduce it if you sent over your project files or, you could download the Project Files again from the course.

yes my app theme is Theme.AppCompat.Light.DarkActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>

The thing is I am extending ListActivity because I have a list that I want to display but I also want to have the action bar. The problem right now is that I am extending ListActivity but I want to also have an action bar but I am not sure how to do that.

It seems like in Android Studio extending ListActivity will ignore the apptheme.

extended ActionBarActivity first then in your xml for the list do not use the default android list id, set the id for you list to some diffrent id of your choice then go back to your activity and refrence the id which you just changed

Adding the following to the activity in the Manifest file seems to do the magic.

android:theme="@android:style/Theme.Holo.Light.DarkActionBar"

How do you fix this replacing the theme with that line did not help...

i think you would have to try to set the actionbar in you code on each activity you want it to appear

since you are extending list, then it think within you code after you have initialized your actvivty view. it would how set the actionbar i your code. am not on my android devlopment. and it also depends if you want your actionbar to support api 8

Hi harry,

Do you think you can help me out.

my program compiles fine. I can take a picture or a 10 sec video. Then I press ok on the picture or video, Im able to choose my friends from a list of my added friends.

The problem is that there is no actionbar displayed and with no actionbar there is no send button displayed as it is involved with the actionbar. Since the release of this video things have been deprecated and the course is outdated.

Do you have any informantion on how to deal with my problem so i can move onto the next part.

Thank you, TheBigOso

here is my github https://github.com/TheBigOso/RibbitSendButton

RecipientsActivity.Java

package com.fartyou.thedirtyappstore.ribbit2;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import java.util.List;

public class RecipientsActivity extends ListActivity {

    public static final String TAG = RecipientsActivity.class.getSimpleName();
    protected List<ParseUser> mFriends;
    protected ParseRelation<ParseUser> mFriendsRelation;
    protected ParseUser mCurrentUser;
    protected MenuItem mSendMenuItem;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_recipients);
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    }

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

        mCurrentUser = ParseUser.getCurrentUser();
        mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
            @Override
            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();
                        i++;
                    }
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                            getListView().getContext(),
                            android.R.layout.simple_list_item_checked,
                            usernames);
                    setListAdapter(adapter);
                } else {
                    Log.e(TAG, e.getMessage());
                    AlertDialog.Builder builder = new AlertDialog.Builder(RecipientsActivity.this);
                    builder.setMessage(e.getMessage())
                            .setTitle(R.string.error_title)
                            .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            }
        });
    }
}

activity_recipients.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.fartyou.thedirtyappstore.ribbit2.RecipientsActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@android:id/list"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@android:id/empty"
        android:text="@string/empty_recipients_list_message"
        />
</RelativeLayout>
Harry James
Harry James
14,780 Points

Hey TheBigoso!

Thanks for the GitHub link there! I've gone ahead and forked your project.

I'll get back to you over on GitHub with a pull request for your project once I've fixed the issue for you :)

Awesome!!! your the best!!!