滚动列表视图导致按钮被无形 [英] scrolling listview causes buttons to be invisible
问题描述
我有包含列表的每一行中的一个按钮的列表视图。 基于一个领域,我想使这个按钮不可见的。
I have a list view which contains a button in each row of the list. Based upon a field, I want to make this button invisible.
我getView内部适配器方法如下所示。
My getView method inside adapter is shown below.
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Activity activity = (Activity) getContext();
View view = convertView;
if (convertView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
view = inflater.inflate(R.layout.listrow, null);
}
final Details details = getItem(position);
Button btn = (Button) view.findViewById(R.id.btn);
if(details.check()) {
btn.setVisibility(View.INVISIBLE);
}
}
当我加载该页面中的数据来自正确。但是,当简单地通过这个列表中滚动,那么这个按钮是越来越看不到的。请告诉我这样做的原因是什么?当我删除如果
部分,然后我将获得按钮的所有行,即使我卷轴。有什么问题给无形
在 getView()
。请回复。先谢谢了。
When I load this page the data comes correctly. But when simply scroll through this list, then this button is getting invisible. Whats the reason for this? When I remove that if
section, then i will get buttons for all rows, even if i scrolls. Is there any problem giving invisible
inside getView()
. Please reply. Thanks in advance.
推荐答案
添加以下内容:
if(details.check()) {
btn.setVisibility(View.INVISIBLE);
}
else {
btn.setVisibility(View.VISIBLE);
}
和......那不如用
and...it had better use
LayoutInflater.from(getContext())
代替
activity.getLayoutInflater()
这篇关于滚动列表视图导致按钮被无形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!