Using ListView : How to add a header view?

前端 未结 3 2049
无人及你
无人及你 2020-11-27 03:54

I looke at the ListView API and I saw the method:

addHeaderView(View v)

What I want to do is to have a layout above the list,

3条回答
  •  离开以前
    2020-11-27 04:44

    You can add as many headers as you like by calling addHeaderView() multiple times. You have to do it before setting the adapter to the list view.

    And yes you can add header something like this way:

    LayoutInflater inflater = getLayoutInflater();
    ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, myListView, false);
    myListView.addHeaderView(header, null, false);
    

提交回复
热议问题