Jana
Jana

Reputation: 1

Android ListView scroll to select a item?

I used the ListView with 4 items. when i click on the ListView items it shows the current selected item. But i need to implement the Scroll Listener to select the items in ListView . When i scroll the ListView it shows current scrolled item ? Any one help me with this

Upvotes: 0

Views: 352

Answers (2)

Santosh Pandey
Santosh Pandey

Reputation: 190

Override the OnScrollListener method in your ListView Listener

list.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {




        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

            if (list.getLastVisiblePosition() == totalItemCount - 1
                    ) {

                Toast.makeText(getActivity(), "Last", Toast.LENGTH_SHORT)
                        .show();


                try {

                } catch (Exception e) {
                }

            }

        }
    });

Upvotes: 1

AndyN
AndyN

Reputation: 1754

Implement OnScrollListener for your ListView

@Override
public void onScroll(AbsListView absListView, int firstVisible, int visibleCount, int totalCount) { 
    //firstvisible is your first visible item in the list
}

Upvotes: 0

Related Questions