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!

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

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Inside the onCreate() method, declare an ArrayAdapter named adapter and initialize it with its constructor. Remember tha

"Inside the onCreate() method, declare an ArrayAdapter named adapter and initialize it with its constructor. Remember that ArrayAdapter is a generic, meaning that the type of the items in the array needs to be specified in angle brackets. The constructor takes three parameters: 1) the context (use this), 2) the layout (use android.R.layout.simple_list_item_1) and 3) the array to adapt (use mApps). Can someone please send me the answer?" i am doing exactly as on the course, doesn't accept it?

AppListActivity.java
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);
    }
}
Henrik Hansen
Henrik Hansen
23,176 Points

Can you please add the code you are trying to submit as answer?

4 Answers

Henrik Hansen
Henrik Hansen
23,176 Points
String[] mApps = {"Instagram", "Pinterest", "Pocket", "Twitter" };

// It is spelled ArrayAdapter, and should include the type within <> as well
ArrayAdopter adopter = new ArrayAdopter(this android.R.layout.simple_list_item_1, mApps);

// Try if this works:
ArrayAdapter<String> adopter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mApps);

setListAdapter(adopter);
Henrik Hansen
Henrik Hansen
23,176 Points

Oh, and i forgot... the ArrayAdapter variable should be named "adapter", not adopter...

thank u so much

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

String[] mApps = {"Instagram","Pinterest","Pocket","Twitter" }; ArrayAdopter<String>adopter=new ArrayAdopter<String>(this android.R.layout.simple_list_item_1, mApps); setListAdpter(adopter);

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Thanks a lot Henrik, i passed it

Henrik Hansen
Henrik Hansen
23,176 Points

Glad I could help! :) Please mark your question as Answered.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

I don't know what to do, thanks a lot for the help in advance.