Static title in ListView, CustomBaseAdapter

Hi everyone, I am trying to create a static title in my ListView related to CustomBaseAdapter.

I want the title to stay on top and not scroll with ListView. Other elements should disappear under the heading if I scroll through the list.

The header is set via the xml file (lvheader) I made. The title is displayed correctly above my ListView, but it is not static and scrolls the ListView.

Can someone please help me with this? thanks in advance

I was already looking for stackoverflow to get some ideas, here is the result.

Add a title to the ListView in my Main.xml:

ListView kp = (ListView)findViewById(R.id.listvw); LayoutInflater inflater = getLayoutInflater(); ViewGroup header = (ViewGroup)inflater.inflate(R.layout.lvheader, kp, false); kp.addHeaderView(header, null, false); ArrayList<SearchResults> searchResults = GetSearchResults(); kp.setAdapter(new MyCustomBaseAdapter(AndroidLogin.this, searchResults, icons)); ... } 
+4
source share
3 answers

Afaik, everything addHeaderView () does adds an item at the top of the list, but it should not make it unscrollable. If you want to commit an element, it looks like you should have two views arranged in a vertical LinearLayout: the upper part is the fixed part, and the bottom is a ListView.

+4
source

I think you should share the title with Listview.

0
source

Use addHeaderView () :

public void addHeaderView (view v)

C: API Level 1 Add a fixed view that appears at the top of the list. If addHeaderView is called more than once, the views will be displayed in the order in which they were added. Views added with this call can have focus if they want to. NOTE. Call this before calling setAdapter. This is how a ListView can wrap a supplied cursor with one that also has an account for headers and footers.

-1
source

Source: https://habr.com/ru/post/1382366/


All Articles