I have created a custom layout for ListFragment
, using the default ArrayAdapter
. My problem is that the empty message is displayed on each row, when the list is not empty (when the list is empty, the message is displayed only once as expected).
headline_list.xml (i.e. my custom layout file)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@id/android:list" />
<TextView android:id="@+id/my_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@id/android:empty"
android:text="There are no data"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
HeadlineFragment.java
public class HeadlineFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.headline_list, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<String> headlines = ...; // populate headlines list
setListAdapter(new ArrayAdapter<String>(getActivity(),
R.layout.headline_list, R.id.my_text, headlines));
}
}