26
votes
  • public static final int listPreferredItemHeight

Ok, of course I understand this part of the expression...listPreferredItemHeight is the preferred list item height.

But I really don't get these stuff. Anyone can point me to the right direction where I can read about that?

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

the example where I find this code is here https://android-developers.googleblog.com/2009/02/android-layout-tricks-1.html

EDIT: in the example at the link the code is android:layout_height="?android:attr/listPreferredItemHeight". What exactly does it mean?

2

2 Answers

62
votes

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.

8
votes

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