I had this problem and couldn't solve it in Java code. The problem was with my xml.
I was trying to add a textView to a container, but had wrapped the textView inside a LinearLayout.
This was the original xml file:
<?xml version="1.0" encoding="utf-8"?>_x000D_
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"_x000D_
android:orientation="vertical"_x000D_
android:layout_width="match_parent"_x000D_
android:layout_height="match_parent">_x000D_
_x000D_
<TextView xmlns:android="http://schemas.android.com/apk/res/android"_x000D_
android:id="@android:id/text1"_x000D_
android:layout_width="match_parent"_x000D_
android:layout_height="wrap_content"_x000D_
android:textAppearance="?android:attr/textAppearanceListItemSmall"_x000D_
android:gravity="center_vertical"_x000D_
android:paddingLeft="16dp"_x000D_
android:paddingRight="16dp"_x000D_
android:textColor="#fff"_x000D_
android:background="?android:attr/activatedBackgroundIndicator"_x000D_
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>_x000D_
_x000D_
</LinearLayout>
_x000D_
Now with the LinearLayout removed:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"_x000D_
android:id="@android:id/text1"_x000D_
android:layout_width="match_parent"_x000D_
android:layout_height="wrap_content"_x000D_
android:textAppearance="?android:attr/textAppearanceListItemSmall"_x000D_
android:gravity="center_vertical"_x000D_
android:paddingLeft="16dp"_x000D_
android:paddingRight="16dp"_x000D_
android:textColor="#fff"_x000D_
android:background="?android:attr/activatedBackgroundIndicator"_x000D_
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
_x000D_
This didn't seem like much to me but it did the trick, and I didn't change my Java code at all. It was all in the xml.