2015-02-03 4 views
0

У меня есть список с нижним колонтитулом в действии. То, что я хочу сделать, - это добавить текстовое представление в нижний колонтитул программно.Как добавить динамический вид в Android

Есть Activity.java, Activity.xml, footer.xml

Часть OnCreate Activty.java (в) метод:

 LinearLayout layout = (LinearLayout)View.inflate(this, R.layout.footer, null); 
     TextView tv = new TextView(this); 
     tv.setText("added text"); 
     tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 
     tv.setVisibility(View.VISIBLE); 
     layout.addView(tv); 

     View footer = getLayoutInflater().inflate(R.layout.refer_footer, null, false); 
     listView.addFooterView(footer); 

     listView.setAdapter(adapter); 

Activity.xml:

<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> 

Но я не могу найти добавленный текст в приложении. Кто-то, пожалуйста, помогите.

+0

вы не используете этот 'LinearLayout layout' объект, и' footer.xml' вы вывесили не имеет никакого значения, так как вы вызываете 'listView.addFooterView (сноска),' 'с этим R.layout.refer_footer' раскладка. – njzk2

ответ

0

Попробуйте создать экземпляр TextView и добавить его в свой адаптер ListView.

ListView listView = .. //create your list, or inflate it from xml... 
TextView footerView = new TextView(activity.getApplicationContext()); 
listView.addFooterView(footerView); 
listView.setAdapter(myAdapter); 
Смежные вопросы