today engage in a long time, was basically solved the problem .
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent" >
4
5 <ListView
6 android:id="@android:id/list" <!--这样命名我就不多说了-->
7 style="@style/MyListView"
8 android:layout_width="match_parent"
9 android:layout_height="match_parent"/>
10
11 <TextView
12 android:id="@android:id/empty" <!-- 为什么这样命名,且看下文 -->
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:layout_gravity="center"/>
16
17 </FrameLayout>
//且看源码ListFragment
1 private void ensureList() {
2 if (mList != null) {
3 return;
4 }
5 View root = getView();
6 if (root == null) {
7 throw new IllegalStateException("Content view not yet created");
8 }
9 if (root instanceof ListView) {
10 mList = (ListView)root;
11 } else {
12 mStandardEmptyView = (TextView)root.findViewById(INTERNAL_EMPTY_ID);
13 if (mStandardEmptyView == null) {
14 mEmptyView = root.findViewById(android.R.id.empty); //且看这里
15 } else {
16 mStandardEmptyView.setVisibility(View.GONE);
17 }
18 mProgressContainer = root.findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
19 mListContainer = root.findViewById(INTERNAL_LIST_CONTAINER_ID);
20 View rawListView = root.findViewById(android.R.id.list);
21 if (!(rawListView instanceof ListView)) {
22 if (rawListView == null) {
23 throw new RuntimeException(
24 "Your content must have a ListView whose id attribute is " +
25 "'android.R.id.list'");
26 }
27 throw new RuntimeException(
28 "Content has view with id attribute 'android.R.id.list' "
29 + "that is not a ListView class");
30 }
31 mList = (ListView)rawListView;
32 if (mEmptyView != null) {
33 mList.setEmptyView(mEmptyView);
34 } else if (mEmptyText != null) {
35 mStandardEmptyView.setText(mEmptyText);
36 mList.setEmptyView(mStandardEmptyView);
37 }
38 }
39 mListShown = true;
40 mList.setOnItemClickListener(mOnClickListener);
41 if (mAdapter != null) {
42 ListAdapter adapter = mAdapter;
43 mAdapter = null;
44 setListAdapter(adapter);
45 } else {
46 // We are starting without an adapter, so assume we won't
47 // have our data right away and start with the progress indicator.
48 if (mProgressContainer != null) {
49 setListShown(false, false);
50 }
51 }
52 mHandler.post(mRequestFocus);
53 }
in the program
1 ((TextView)getListView().getEmptyView()).setText(getString(R.string.list_no_data));
so successful .
Why not use setEmptyText (CharSequence text) anyway, tried for a long time without success. did not know
static final int INTERNAL_EMPTY_ID = 0x00ff0001;
represent what the various test without success , google, degree of your mother for a long time , alas ..... I hope you know , please enlighten me !
没有评论:
发表评论