0

I am trying to find a good ListView that supports "Pull to Refresh" and "Load more" that works with gradle, works with a bit older APIs ( I currently use the "LoadMoreListView" that requires min API18) and is NOT deprecated...all I can find are depreacted libraries that noone cares about anymore... Any suggestions?

2 Answers 2

2
AbsListView.OnScrollListener listenerScroll = new AbsListView.OnScrollListener() {

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        Log.d("TAG", "onScrollStateChanged");
    }

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

        boolean loadMore = firstVisibleItem + visibleItemCount >= totalItemCount;
        Log.d("TAG", "onScroll " + loadMore + " " + totalItemCount + " ");

        if (loadMore && !mIsLoading && !isLoadFinish) {

            if (mTrackDataValues != null && mTrackDataValues.size() > 0) {
                callAPIHistory(mTrackDataValues.get(mTrackDataValues.size() - 1).getDateFor());
            }

        }

    }
};
2
  • Thank you. I know about that and how to do it custom, BUT I want an easy solution mainly for the "pull to refresh" that when you pull it down it shows a view that says "Loading" or something like that.
    – Panos
    Mar 9, 2016 at 2:02
  • You can use CustomSwipeRefreshLayout to pull to refresh . swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { Log.d("Swipe", "Refreshing Physician"); //stopping swipe refresh swipeView.setRefreshing(false); // refresh the physician list requestPhysicianAPI(mSortBy, mIsDescending); } }); Mar 9, 2016 at 2:08
1

You can modify this code to suit your requirement. This class makes use of SwipeRefreshLayout

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{
private ListView mListView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private List<String> mObjectList;
private StringAdapter mStringAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mObjectList = new ArrayList<String>();
    mObjectList.add("Sweden");
    mObjectList.add("Denmark");
    mObjectList.add("Finland");
    mObjectList.add("Norway");
    mObjectList.add("Iceland");
    mListView = (ListView)findViewById(R.id.listView);
    mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe_refresh_layout);
    mStringAdapter = new StringAdapter(MainActivity.this, mObjectList);
    mListView.setAdapter(mStringAdapter);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setDistanceToTriggerSync(30);
    mSwipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT);
}
Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        //super.handleMessage(msg);

        // add new data source to the adapter

        mStringAdapter = new StringAdapter(MainActivity.this, mObjectList);
        mListView.setAdapter(mStringAdapter);
        mSwipeRefreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mSwipeRefreshLayout.setRefreshing(false);
            }
        }, 1000);
    }
};
@Override
public void onRefresh() {
    mSwipeRefreshLayout.postDelayed(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
            mHandler.sendEmptyMessage(0);
        }
    }, 1000);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.