【发布时间】:2015-11-01 01:11:12
【问题描述】:
我正在为我的 Android 应用程序创建一个自定义 ListFragment。我想在@id/listContainer 中添加一个孩子。但我无法使用findViewById(android.R.id.listContainer) 获取对视图的引用。
这是ListFragment 的默认布局。
list_content.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/progressContainer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:gravity="center">
<ProgressBar style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/loading"
android:paddingTop="4dip"
android:singleLine="true" />
</LinearLayout>
<FrameLayout android:id="@+id/listContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView android:id="@+android:id/internalEmpty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>
</FrameLayout>
这是我自定义的ListFragment 代码。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(android.R.layout.list_content, container, false);
ProgressBar progressBar = new ProgressBar(getActivity());
progressBar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
progressBar.setIndeterminate(true);
ViewGroup listContainer = (ViewGroup) view.findViewById(android.R.id.listContainer);
listContainer.addView(progressBar);
return view;
}
Android Studio 说error: cannot find symbol variable listContainer。
我做错了什么?
【问题讨论】:
标签: android android-layout android-fragments android-listfragment