2014-10-17 80 views
1

我一直在嘗試膨脹下面的xml文件,但沒有運氣,請指向正確的方向。我需要充氣,然後將其添加到我的陣列適配器。如何充氣textView作爲佈局

 TextView footerView = null; 
     View row = null; 



     if (null == footerView) { 

      LayoutInflater inflater = getLayoutInflater(); 
      row = inflater.inflate(R.layout.footer_view,null); 
      footerView = (TextView)row.findViewById(R.id.footerView); 
      setContentView(footerView); 


      return; 
     } 


     getListView().addFooterView(footerView); 


<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/footerView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:text="@string/add_new_todo_item_string" 
    android:textSize="24sp" > 

</TextView> 
+0

請解釋一下,完整,準確地說,「不具有運氣」的意思。 – CommonsWare 2014-10-17 20:56:05

+0

我試圖在模擬器屏幕上顯示這個。 add_new_todo_item_string – 2014-10-17 20:58:32

+0

使用setContentView重置活動的所有視圖,因此getListView無法執行任何操作 – Benoit 2014-10-17 21:00:55

回答

2

解決 下面的代碼工作,解決我的問題

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View row = inflater.inflate(R.layout.footer_view, getListView(), false); 
    footerView = (TextView) row.findViewById(R.id.footerView); 

    // TODO - Add footerView to ListView 

    getListView().addFooterView(footerView);