2012-04-25 81 views
1

我在名爲footer.xml的佈局中有一個imageview,它實際上被添加爲listview.I的頁腳,我需要在listview結尾處動態顯示圖像。因此,我已經將imageview引用我的Java文件,如下imageview.setBackgroundResource上的空指針

ImageView footerimage; 
    View footerView = getLayoutInflater().inflate(R.layout.footer, null);//This is the footer layout which i have added to the listview 
    footerimage = (ImageView)findViewById(R.id.im); 
    footerimage.setBackgroundResource(images[i]);//images is an integer array which has drawable resources and i value is not null. 
    lv.addFooterView(footerView, null, false); 

我在上面code.I的第四行得到一個空指針異常也改變了圖像[一] R.drawable.someimage但NPE仍然存在。 下面是我的頁腳佈局

<?xml version="1.0" encoding="utf-8"?> 

<ImageView 
    android:id="@+id/im" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true"   
    android:contentDescription="@string/app_name" /> 

任何建議都提前appreciated.Thanks

回答

7

我想這應該是:

footerimage = (ImageView) footerView.findViewById(R.id.im); 
+0

是你是正確的 – 2012-04-25 05:53:43

+0

謝謝你的答案糖果...我覺得真的很愚蠢。 – 2012-04-25 06:10:47