what ?android:attr/listPreferredItemHeight is doing and how?

The marker "?" means that you are referring to a style attribute. So ?android:attr/listPreferredItemHeight simply means "use the value defined by the attribute called listPreferredItemHeight in the namespace android."

This attribute and its value are part of the Android framework, hence the "android" namespace.


android:layout_height="?android:attr/listPreferredItemHeight"

?[<package_name>:][<resource_type>/]<resource_name> taken from Referencing Styles.

The ? is used for referencing style attributes, where as the more familiar looking@ is used for normal resources.

Style attribute resources reference values in the currently applied theme. So values may differ between different themes.

The value of listPrefferedItemHeight, found in the android package of the currently applied theme is returned to android:layout_height. The resource type attr in the line of code above is optional and can be omitted. Therefore, the following is also correct:

?android:listPreferredItemHeight

Tags:

Java

Android