如何在Android中动态添加视图
我在活动中有一个带页脚的列表视图。我想做的是以编程方式向页脚添加textview 有Activity.java,Activity.xml,footer.xml java的onCreate()方法的一部分: Activity.xml:如何在Android中动态添加视图,android,android-layout,view,Android,Android Layout,View,我在活动中有一个带页脚的列表视图。我想做的是以编程方式向页脚添加textview 有Activity.java,Activity.xml,footer.xml java的onCreate()方法的一部分: Activity.xml: <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientatio
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="@+id/referList"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
footer.xml:
<LinearLayout
android:id="@+id/footer_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
</LinearLayout>
但我在应用程序中找不到添加的文本视图。请有人帮忙。尝试创建TextView实例并将其添加到ListView适配器
ListView listView = .. //create your list, or inflate it from xml...
TextView footerView = new TextView(activity.getApplicationContext());
listView.addFooterView(footerView);
listView.setAdapter(myAdapter);
您没有使用此
LinearLayout布局
对象,您发布的footer.xml
与此无关,因为您正在调用listView.addFooterView(footer)代码>使用此R.layout。请参阅页脚。
ListView listView = .. //create your list, or inflate it from xml...
TextView footerView = new TextView(activity.getApplicationContext());
listView.addFooterView(footerView);
listView.setAdapter(myAdapter);