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

appcompat_v7 and main activity class questions (Blog Reader)

Ok, here comes something that the videos dont show: the support library "appcompat v7". I know its a library because of google, nothing else, and the point is, with every project i have created (MasterDetail and BlogReader) eclipse creates one new appcompat v7 (appcompat v7_2, appcompat v7_3, etc). and always have the same content (folders and more).

Is this normal????

More things, when eclipse creates the Blog Reader folders, the first thing i see in the main class is:

public class MainListActivity extends ActionBarActivity

With of course, a couple of imports from the appcompat v7:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;

Nice eh??? Well now i need someone to explain me how to deal with these librarys and the main please, because in Ben's videos we dont seen nothing about this...

First thing i did was coment some lines and methods that eclipse creates by himself. I'll leave you the original code from Eclipse: And as you can see in the main method, i have the extends fromActionBarActivity instead of activity.

Help please help...

package com.lodo.blogreader;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainListActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_list, menu);
        return true;
    }

    @Override
    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);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

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

}

3 Answers

Arel Sapir
Arel Sapir
7,979 Points

i havnt fully read the whole thing but Eclipse problems can be caused by not updating your SDK tools and if one needed SDK tool is not installed many freaky things can heapen, so for start i suggest downloading all SDK tools from your SDK manager and make sure they are installed properly

thanks for your answer but mmmmm i dont think that was the problem, i have all the apis, tool, extras and etc installed... I tried another thing, and maybe you guys coul know about it, the thing is in the video Ben sets the Min SDK with API 8 (2.2 froyo), and if i follow all the steps, then, the appcompat apears with the project. But if i select the API 16 (JellyBean, the most used iin this moment) as de Min SDk, it doesnt apears...and the main class looks like this: And of course, as Arel comented, the first time Eclipse created my project without the main java doc activity and the seccond time works properly...

Any android magician who can explain it to me please??

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

This was a change in the Android development tools which makes things a bit different than our videos. It's unfortunate, but we can work around it and get back in the right place. I've recorded some new versions of the beginning videos that should help going forward.

The appcompat library is added and required when supporting older versions of Android. There are two solutions:

1) Change the min SDK to 14 or greater. Newer versions don't require the support library (appcompat).

2) Modify the code to work with the appcompat library. You shouldn't need to change anything, though some things in our videos now cause problems. I have recorded fixes where appropriate as well as added notes in the Teacher's Notes section in a few places.

The biggest issue is that new PlaceholderFragment that is introduced. Check out the Teacher's Notes for how to remove the Fragment, and my video fix should be available tomorrow or Wednesday. http://teamtreehouse.com/library/build-a-blog-reader-android-app/rebuilding-from-scratch/creating-the-project-and-listactivity-2