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);
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论