gpt4 book ai didi

java - Android 列表页脚

转载 作者:行者123 更新时间:2023-11-29 22:23:28 24 4
gpt4 key购买 nike

我在代码的第 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 不是我的事。

我会在正确答案上打勾!

最佳答案

不是使用 ActivityView 中的 findViewById() 方法,您应该分配(我假设是页脚 TextView 在你的 R.layout.footer_row 中)来自膨胀的 ViewTextView

示例代码:

TextView tv_footer = (TextView) header.findViewById(R.id.tv_footertext);

关于java - Android 列表页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6558470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com