1

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?

2
  • I have retagged -android -listview -layout +java since your question is more related to Java package usage. Commented Nov 21, 2011 at 18:43
  • I realize from the answers my question wasn't as clear as I thought it was. Hope the edit helps. Commented Nov 21, 2011 at 19:19

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.