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.
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);
}
}
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 prob开发者_运维问答lem giving invisible
inside getView()
. Please reply. Thanks in advance.
Add the following:
if(details.check()) {
btn.setVisibility(View.INVISIBLE);
}
else {
btn.setVisibility(View.VISIBLE);
}
and...it had better use
LayoutInflater.from(getContext())
instead of activity.getLayoutInflater()
set the clickable property of listview false in xml or like:
getListView().setClickable(false);
精彩评论