我在代码的第 5/7 行遇到空指针异常:
LayoutInflater inflater = getLayoutInflater();
View header = inflater.inflate(R.layout.footer_row, (ViewGroup) findViewById(R.id.header_layout_root));
TextView tv_footer = (TextView) findViewById(R.id.tv_footertext);
if(getListView().getCount()<=8) {
tv_footer.setText("You have no more assignments");
} else {
tv_footer.setText(Integer.toString(getListView().getCount()) + " assignments shown");
}
getListView().addFooterView(header, null, false);
我不太清楚为什么,你能告诉我吗? ListView 不是我的事。
我会在正确答案上打勾!
最佳答案
不是使用 Activity
的 View
中的 findViewById()
方法,您应该分配(我假设是页脚 TextView
在你的 R.layout.footer_row
中)来自膨胀的 View
的 TextView
。
示例代码:
TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);
关于java - Android 列表页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558470/