in Education by
I'm having some problems when trying to remove the header from a listView. At first I use addHeaderView() to add it, but when I change to another layout I want it to disappear but removeHeaderView() doesn't work... I also tried setting visibility to GONE and it doesn't disappear... What can I do? Thanks in advance JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Try the approach mentioned below.. Android ListView#addHeaderView and ListView#addFooterView methods are strange: you have to add the header and footer Views before you set the ListView's adapter so the ListView can take the headers and footers into consideration -- you get an exception otherwise. Here we add a ProgressBar (spinner) as the headerView: // spinner is a ProgressBar listView.addHeaderView(spinner); We'd like to be able to show and hide that spinner at will, but removing it outright is dangerous because we'd never be able to add it again without destroying the ListView -- remember, we can't addHeaderView after we've it's adapter: listView.removeHeaderView(spinner); //dangerous! So let's hide it! Turns out that's hard, too. Just hiding the spinner view itself results in an empty, but still visible, header area. Now try to hide the spinner: spinner.setVisibility(View.GONE); Result: header area still visible with an ugly space: The solution is to put the progress bar in a LinearLayout that wraps it's content, and hiding the content. That way the wrapping LinearLayout will collapse when its content is hidden, resulting in a headerView that is technically still present, but 0dip high: <!-- simplified --> Then, set the layout as the header: spinnerLayout = getLayoutInflater().inflate(R.layout.header_view_spinner, null); listView.addHeaderView(spinnerLayout); And when we need to hide it, hide the layout's content, not the layout: spinnerLayout.findViewById(R.id.spinner).setVisibility(View.GONE); Now the header disappears from view. No more ugly space at the top!

Related questions

0 votes
    I have a listView in my application and at some point during the execution, I want to highlight a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I'm beeing bit confused here. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.bugs_list_item, ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    In My Activity there are more then one ListView. See the XML Layout of it: Now i am able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I am having the code like In which I will bind the value for checkbox dynamically from db at buttonclick ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I am having the code like In which I will bind the value for checkbox dynamically from db at buttonclick ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I am developing a Windows 8 metro application that uses semantic zoom in the following way: The zoomed in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    I'm using SafetyNet API for checking if device is rooted or not and using the below helpful code but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I'm trying to fetch some data from the REST API of HP Alm. It works pretty well with a small ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I want to disable the sort property in dataTable API. I use bsort:false to disable sorting from all ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I had to add some ugly links in my website that looks like: "/page/?utm_source=value&utm_source= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm totally new to Xamarin, so please be patient! Somehow Xamarin adds a mysterious Margin to all my ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    Hi I want to remove last comma from a line. For example: Input: This,is,a,test Desired Output: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
...