Java Android列表页脚
我在代码的第五行/第七行得到一个空指针异常:Java Android列表页脚,java,android,Java,Android,我在代码的第五行/第七行得到一个空指针异常: 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)
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);
LayoutInflater充气机=getLayoutInflater();
视图页眉=充气器。充气(R.layout.footer\u行,(视图组)findViewById(R.id.header\u layout\u根));
TextView tv\u footer=(TextView)findViewById(R.id.tv\u footertext);
如果(getListView().getCount()而不是从活动的视图中使用findViewById()
方法,则应该从膨胀的视图中指定文本视图(我假定它是R.layout.footer行
中的页脚TextView
)
示例代码:
TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);
更改下面指定的代码的第三行。因为膨胀视图包含指定的textView
TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);
谢谢。你能发布logcat信息吗,似乎没有设置tv\u页脚值,可能是R.id.tv\u页脚文本不是你在setContentView(..)方法中设置的布局部分。请检查一下。最好提供详细的代码(因为你发布的代码看起来不错)没错,但另一个人先回答,所以得到了勾号。无论如何,谢谢你!无论如何,我感谢你点击上面的三角形。:)。