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 trialZubeyr Aciksari
21,074 PointsInside 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?
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);
}
}
4 Answers
Henrik Hansen
23,176 PointsString[] 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
23,176 PointsOh, and i forgot... the ArrayAdapter variable should be named "adapter", not adopter...
MUZ140828 Tendayi Munodawafa
4,154 Pointsthank u so much
Zubeyr Aciksari
21,074 PointsString[] mApps = {"Instagram","Pinterest","Pocket","Twitter" }; ArrayAdopter<String>adopter=new ArrayAdopter<String>(this android.R.layout.simple_list_item_1, mApps); setListAdpter(adopter);
Zubeyr Aciksari
21,074 PointsThanks a lot Henrik, i passed it
Henrik Hansen
23,176 PointsGlad I could help! :) Please mark your question as Answered.
Zubeyr Aciksari
21,074 PointsI don't know what to do, thanks a lot for the help in advance.
Henrik Hansen
23,176 PointsHenrik Hansen
23,176 PointsCan you please add the code you are trying to submit as answer?