How can I make the first visible element of the ListView
having a different layout
from the others.
I have created a custom adapter with 2 different layouts. Now, how can I make the layout
change when the item comes in the first position
?
to get the the first item of the listview having a different layout the following code can be used. But the listview don't move when the items in the list are less than the no of visible items.
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
if(firstItem != firstVisibleItem)
{
firstItem = firstVisibleItem;
adapter.notifyDataSetChanged();
}
}
});
and inside the adapter class check if the postion
is same as firstItem
if its equal then show the detals layout.
Try this
int visibleposition = ListView.getFirstVisiblePosition();
now for this particular position change the background of the list item like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With