Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom ListView adapter with default Android themes

I'm developing an app on Honeycomb with a ListView. When using a normal ArrayAdapter to feed the ListView content, I can pass it a built-in layout such as Android.R.layout.simple_selectable_list_item. This creates a clickable item with a nice fading animation when selecting an item that is consistent with the overall Honeycomb feel.

However, if I decide to use my own custom layout (or to create a custom adapter), I no longer have any animation when focusing on or selecting an item in the ListView. I could construct my own animation, but I would prefer to use the default Holo theme when developing for Honeycomb for simplicity and consistency.

I'm at a loss for how to do this and haven't been able to find anyone else with my struggle (perhaps I'm searching the wrong terms, or am missing something obvious!). Does anyone have any suggestions? I figure it involves identifying some sort of style or theme in the XML file for the layout, but I haven't figured out where to put that or what the contents might be.

Thanks!

like image 822
jlugo Avatar asked Jun 21 '11 07:06

jlugo


People also ask

How to add custom adapter for my listview in Android?

This example demonstrates how do I add custom adapter for my listView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.java

What is the use of custom_list_view layout in listview?

For every single item in the ListView this layout creates the following view for every single item in the array adapter. By creating this custom class we invoke the getter and setter manually for the custom_list_view layout.

How to make Android listview load faster?

Android ListView with Custom Adapter and ViewHolder. In this Android list view sample, it demonstrates list view using custom array adapter with view holder. ViewHolder makes the list view to load faster by caching the views. If it look up the view every time by calling the findViewById(), it will be very slow.

How to optimize listview using viewholder pattern?

It also explains about how to optimize listview using ViewHolder pattern. An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. ArrayAdapter links the array to the Adapter View.


1 Answers

Got it: I had to remove all references to android:listSelector and android:background for my ListView. Then I added

android:background=?android:attr/listChoiceBackgroundIndicator

to my top-level view for the ListView row layout.

like image 119
jlugo Avatar answered Oct 23 '22 04:10

jlugo