0

I have a requirement that I need to display a custom ListView with 'N' elements(Size of ListView may vary). I need to display how many elements user has viewed/ scrolled from my Listview...

My requirement is to I nned to display user that how many List items user not viewed yet..

Please let me know how get the count of elemnts...

4

2 回答 2

0
// class members
private TextView textView;
private in maxViewed = 0;

// in your onCreate method   
// find pointer to where you are displaying to user how many items he's viewed
textView = (TextView)findViewById(R.id.textView); // make sure to make this item in your layout

// make the scroll listener for the listview
listView.setOnScrollListener(new OnScrollListener(){

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

    public void onScrollStateChanged(AbsListView view, int scrollState) {   
        // keep track of how many items we've viewed         
        maxViewed = Math.max(maxViewed, listView.getLastVisiblePosition());
        textView.setText(String.valueOf(maxViewed));
    }

});
于 2012-04-25T23:03:15.790 回答
0

您可以使用listView.getLastVisiblePosition(),它会告诉您在您的最底部可见项目的位置ListView

于 2012-04-25T22:15:59.413 回答