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

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Can someone please help me, really stuck here? It ask to set the adapter as a default and to ıse setListAdapter..

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_list); ArrayAdapter<String> adopter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mApps); setListAdapter(Adapter); }

}

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);
        ArrayAdapter<String> adopter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mApps);
        setListAdapter(Adapter);
    }

}

1 Answer

I see two issues.

  1. You have a typo on this line:

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

    It won't stop the app from working, but the variable should be "adapter" rather than "adopter"

  2. You also have a type on this line, which will give you an error.

    setListAdapter(Adapter);
    

    the word "Adapter" should be lower-case, to match the variable defined on the previous line.