caltangelo
caltangelo

Reputation: 274

android default xml layout not loading

I'm trying to make a ListActivity with check boxes using one of the built in android layouts, android.R.layout.simple_list_item_multiple_choice. For background, I'm fetching the list in a private AsyncTask, then calling the adapter like this:

listActivity.setListAdapter(new ArrayAdapter<String>(listActivity, 
    android.R.layout.simple_list_item_multiple_choice, mDisplayList));

However when I run my code, the ListView is displayed with list_item.xml, which I'm using for all the other ListViews in my project. Any idea why this is happening?

Upvotes: 1

Views: 735

Answers (3)

caltangelo
caltangelo

Reputation: 274

The reason the right xml layout wasn't being used was because my AsyncTask was extending my (other) custom AsyncTask that used another xml layout and I left in this line.

super.onPostExecute();

which was at the end of the method so the inherited layout trumped the one I wanted.

Upvotes: 1

Renaud
Renaud

Reputation: 8873

You don't need to import android.R.layout since you invoke it explicitely using android.R.layout.simple_list_item_multiple_choice.

That post may be of use.

Update from comment

It's hard to figure out what's the problem. Did you try to clean your project and rebuild? Sometime android int id's just do strange things if you don't clean the project and regenerate the gen files. But messing android internal references is highly unlikely… If it doesn't work, you may have another polluting setListAdapter somewhere else but it's hard to say without your full project.

Upvotes: 0

WarrenFaith
WarrenFaith

Reputation: 57672

When you use the android R in this way: android.R.layout... than you already have the package android before the class name R.

If you explicitly provide a class name with a complete package name, you don't need to import it, too.

That's for the case that you have the same class name from different packages which happens often when you use the android.R and your generated R class.

Upvotes: 0

Related Questions