2012-04-25 25 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