1

So currently I'm using an ArrayAdapter to populate my listview from my database, like so:

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
            this, R.layout.subject_list_item, mArrayList);
    lv.setAdapter(arrayAdapter);

(mArrayList is a list of the text that will populate the listview, lv.)

Currently, if I want to add a final item to the bottom of the list, I can just append it to the mArrayList, but this will set it's layout to subject_list_item the same as all the other items. Is there an easy way of setting the layout of only the final item to a different layout, say subject_list_item2? I want it in the same list so that it still scrolls with the other items, but I want it to look different.

ankuranurag2
  • 2,300
  • 15
  • 30
Roonil
  • 486
  • 1
  • 4
  • 13
  • @ADM yeah, the top answer to that is definitely what I wanted, cheers. I don't know if I should close this question however, considering the uncertainty in the responses to the question you've linked over whether the user wanted the footer to scroll or not. I'll just accept the answer that links to the relevant answer on that question. – Roonil Jan 16 '19 at 05:43
  • Do the right thing!!! Mark it as duplicate .. – ADM Jan 16 '19 at 05:50

1 Answers1

0

You need to add a footer in your listview (I am assuming your lv means it is a ListView).

Refer : https://stackoverflow.com/a/4265324/783707

To summarize, use this code:

    View footer =  getActivity().inflate(R.layout.footer, null, false);
    lv.addFooterView(footer);
Ankur Aggarwal
  • 2,210
  • 2
  • 34
  • 39