我是新來的android編程。這是我的代碼。請幫助。如何在listview爲空時顯示消息?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
ListView view = (ListView) inflater.inflate(R.layout.fragment_alarms,container, false);
String[] titles = getResources().getStringArray(R.array.drawer_menu_list);
view.setAdapter(new ArrayAdapter<String>(getActivity(),
R.layout.drawer_list_item, titles));
view.setAdapter(mAdapter.setCurrentSeverityAlarm(0));
mListView = view;
mAdapter.refresh(mSpinnerAdapter);
return view;
}
xml文件:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_alarms"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/alarm_list_vertical_margin"
android:paddingLeft="@dimen/alarm_list_horizontal_margin"
android:paddingRight="@dimen/alarm_list_horizontal_margin"
android:paddingTop="@dimen/alarm_list_vertical_margin"
android:divider="@android:color/transparent"
android:dividerHeight="@dimen/alarm_list_divider_height"
android:scrollbars="none">
</ListView>
[如何在android中列表視圖爲空時顯示消息]可能的重複(http://stackoverflow.com/questions/3199904/how-to-display-a-message-when-the-list-視圖是空的在Android) – matiash