How to use a list in Listview Footer?

Asked

Viewed 121 times

3

I added a Footer (footer) in a Listview, but this Footer will contain a list (List<>).

Footer is showing, but is showing only the first item in the list.

How to show the list correctly in Footer?

Example code in Pastebin

lvItens = (ListView) view.findViewById(R.id.lvItens);

List<String> lista = new ArrayList<String>();
lista.add("Item 1");
lista.add("Item 2");
lista.add("Item 3");
lista.add("Item 4");
lista.add("Item 5");

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, lista);

View viewFooter = LayoutInflater.from(getActivity()).inflate(R.layout.listview_footer, null, false);

ListView lvItensFooter = (ListView) viewFooter.findViewById(R.id.lvItens);

List<String> listaFooter = new ArrayList<String>();
listaFooter.add("Footer 1");
listaFooter.add("Footer 2");
listaFooter.add("Footer 3");

ArrayAdapter<String> adapterFooter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, listaFooter);

lvItensFooter.setAdapter(adapterFooter);

lvItens.addFooterView(viewFooter);                      
lvItens.setAdapter(adapter);

Listview-Footer http://felipearon.com.br/img/listview-footer.png

  • 1

    Could include the layout of your Activity that contains this ListView? You could reduce the image size and include the code with the "{}" button in the edit menu.

1 answer

1


Have you tried modifying the code as shown below:

Before:

View viewFooter = LayoutInflater.from(getActivity()).inflate(R.layout.listview_footer, null, false);

Afterward:

View viewFooter = LayoutInflater.from(getActivity()).inflate(R.layout.listview_footer, lvItens, true);

On the site below is an article that shows why it is important to use the layoutInflater in the right way. http://www.doubleencore.com/2013/05/layout-inflation-as-intended/

  • Great article. I’ll run the tests again as you indicated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.