自定义 listPreference 中的双行
使用此处中的代码遇到问题。当手机处于横向方向时,并非所有列表项都可见(假设我只看到 5 个中的 3 个)。当我向下滚动到第四个和第五个元素时,我再次看到两个第一个元素(即 1,2,3,1,1)。经过一些滚动动作后,我得到了更有趣的组合(如 2,3,1,2,1)等等。
代码与链接中的一样,我更改的所有内容都没有解决问题。怎么了?
预先感谢
2Rajath 感谢您提供的简单示例,但我无法将其应用到我的案例中。请看一下,
@Override
public View getView(final int position, View convertView, ViewGroup parent){
View row;
if(convertView == null){
row = mInflater.inflate(R.layout.custom_list_preference_row, parent, false);
} else {
row = convertView;
}
CustomHolder holder = new CustomHolder(row, position);
row.setTag(holder);
return row;
}
当创建 CustomHolder 对象时,它会在 setId() 方法中抛出 NullPointer 异常
class CustomHolder
{
private RadioButton rButton = null;
CustomHolder(View row, int position){
rButton = (RadioButton)row.findViewById(R.id.custom_list_view_row_radio_button);
rButton.setId(position);
rButtonList.add(rButton);
}
}
您能解释一下如何使此代码工作吗?
faced with a problem using code from here. When a phone has a landscape orientation not all list items are visible (let's asume I see only 3 of 5). When I scroll down to 4th and 5th elements I see again two 1st elements (i.e. 1,2,3,1,1). After some scroll actoins I get more interesting mix (like 2,3,1,2,1) and so on.
The code is as was in the link, everything I changed didn't fix a problem. What's wrong?
Thanks in advance
2Rajath
Thank you for the simple example, but I cannot apply it to my case. Please have a look
@Override
public View getView(final int position, View convertView, ViewGroup parent){
View row;
if(convertView == null){
row = mInflater.inflate(R.layout.custom_list_preference_row, parent, false);
} else {
row = convertView;
}
CustomHolder holder = new CustomHolder(row, position);
row.setTag(holder);
return row;
}
When CustomHolder object is created it throws NullPointer exception at setId() method
class CustomHolder
{
private RadioButton rButton = null;
CustomHolder(View row, int position){
rButton = (RadioButton)row.findViewById(R.id.custom_list_view_row_radio_button);
rButton.setId(position);
rButtonList.add(rButton);
}
}
Could you please explain how to make this code work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[根据更新编辑]
正在设置的 id 可能与其他 id 冲突。看看这是否有帮助 - Android: View.setID( int id) 以编程方式 - 如何避免 ID 冲突?。
[edited based on update]
It's possible that the id being set is conflicting with some other id. See if this is helpful - Android: View.setID(int id) programmatically - how to avoid ID conflicts?.