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 Android Lists and Adapters (2015) Standard ListViews Using an ArrayAdapter

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mSongTitles);

this stage is frustrating me... have been stuck for a while. can someone paste the answer please

AppListActivity.java
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;

public class AppListActivity extends ListActivity {

    String[] mApps = {"Instagram","Pinterest","Pocket","Twitter" }; 

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mSongTitles);

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

5 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

The directions say "In the onCreate method" You are not doing it in the onCreate method. I get it also says use <> brackets, which is totally fine. But generics go along with java collections buuuutt if you really think about it. Is a layout ID actually a String? So You have to ask yourself, is the context or "this" a string? So I get it says use <> but you don't actually have to at all. Just forget about em for now lol.

Also, the directions say mApps not mSongTitles. So you have the wrong param too.

The code for both challenges is below. You were super close though

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;

public class AppListActivity extends ListActivity {

    public String[] mApps = {
        "Instagram",
        "Pinterest",
        "Pocket",
        "Twitter"
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_list);

        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mApps);
        setListAdapter(adapter);

    }
}

Please let me know if this answers your question or if you have additional questions on this topic.

Thank you Ryan, this worked.

thanks Ryan Ruscett for rescuing me

Hie Ryan Ruscett please help on this im stuck again

Now we are ready to read the parcel in. In the constructor that takes a Parcel parameter, add code to set the member variables from the Parcel passed in. Remember, use the appropriate read methods based on the types, and order matters!

public class VideoGame implements Parcelable {

public String mTitle = "";
public int mYear = 0;

public VideoGame() {
    // intentionally blank
}

// getters and setters omitted for brevity!

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(mTitle);
    dest.writeInt(mYear);
}

public VideoGame(Parcel in) {
    // Task 1 code here!
}

public static final Creator<VideoGame> CREATOR = new Creator<VideoGame>() {
    @Override
    public VideoGame createFromParcel(Parcel source) {
        // Task 2 code here!
        return null;
    }

    @Override
    public VideoGame[] newArray(int size) {
        // Task 3 code here!
        return new VideoGame[0];
    }
};

}

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

This is a different challenge. I typically go to the challenge and code it out to get my examples to show you. Except this is still linked to the first question. So I am not sure of the exact answer to give you without the code challenge. I mean, I could give you what I think it is but I am not 100 percent sure unless I go through the exercise. ? can you post the link to the exercise and I will answer it for you.