简体   繁体   中英

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?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM