Question

I am making an android app where I will have a custom listarray adapter that adds list view items (no problem here).. however.... I want to be able to add not list-array items (it will be a custom linear layout that is a form) to the list view(i will be translating list items up so the form will be on top). is this possible?

my end result would be so: i want to get list items

I want to click a button

I will use layout inflater to get a view from another xml and then add it to my list view with out passing it through the list adapter.

any help would be great thanks.

Was it helpful?

Solution

This is functionality that you should write into your adapter class. Do not circumvent the adapter. The list view is relying on the adapter to serve up views, and the adapter is performing recycling so that new views don't have to be inflated every time the user scrolls up and down.

Adapters have a couple methods that are designed to let you serve up different views for different list view rows: getItemViewType(int position) and getViewTypeCount(). For every different type of row you want to inflate, have a different private method to do the inflation (or recycling, just like you normally would with the ViewHolder pattern). In your getView() method, call the appropriate private helper to inflate the view, based on what type of list item it is -- your view can be just about anything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top