This example shares the specific code for XListView to implement pull-up loading and pull-down refresh for your reference. The specific content is as follows
## Import XListVIew third-party library files. Insert refresh data into the head of the collection through LinkedList, and put the loaded data into the tail of the collection ## private Context context; private View view; private String path; private XListView xlv; private LinkedList<Data> listData; private Handler handler = new Handler() { @SuppressWarnings("unchecked") public void handleMessage( msg) { int code = msg.arg1; if(msg.arg1==400){ (context, "Data format parsing is incorrect", 0).show(); } else{ NewsFragmentAdapter myAdapter = null; switch (code) { case 0: // default listData = (LinkedList<Data>) ; myAdapter = new NewsFragmentAdapter(context, listData); (myAdapter); break; case 1: LinkedList<Data> shualist = (LinkedList<Data>) ; myAdapter = new NewsFragmentAdapter(context, shualist); for (int i = 0; i < (); i++) { ((i)); } (); stopLoadOrRefresh(); break; case 2: LinkedList<Data> loadlist = (LinkedList<Data>) ; myAdapter = new NewsFragmentAdapter(context, loadlist); for (int i = 0; i < (); i++) { ((i)); } (); stopLoadOrRefresh(); break; default: break; } } }; }; @Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); context=getActivity(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = (, container, false); path = getArguments().getString("path"); // Configure Xlist xlv = (XListView) (); // Get the control (true); // Settings can be refreshed by pulling down (true); // Settings can be loaded xListViewListener(); // Call the XListView's listening method if(path != null){ getMessage(path, 0); // Call method to request data } itemClickListner(); // Call the XListView entry click listening method return view; } private void itemClickListner() { (new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent intent=new Intent(context, ); ("path", (arg2-1).article_url); startActivity(intent); } }); } public void xListViewListener() { (new IXListViewListener() { // Operations implemented when pull-down refresh @Override public void onRefresh() { getMessage(path, 1); // Request the network and load the content of the new request to the collection frontend } // Operation content implemented when loading @Override public void onLoadMore() { // Request the network and load the requested new content to the collection backend getMessage(path, 2); } }); } public void getMessage(String path, final int code) { HttpUtils utils = new HttpUtils(); // Set the refresh interval time, if the default is not set, you can refresh the new content after one minute. (0); (, path, new RequestCallBack<String>() { // Method for requesting a failed callback for network @Override public void onFailure(HttpException arg0, String arg1) { } // Method to request successful callback from the network @Override public void onSuccess(ResponseInfo<String> arg0) { String info = ; Gson gson = new Gson(); LinkedList<Data> list = (info, ).data; Message message = new Message(); if(list != null){ message.arg1 = code; = list; }else{ message.arg1=400; } (message); } }); } private void stopLoadOrRefresh() { // Stop loading (); // Stop refreshing (); //Latest refresh time (getTime()); } public String getTime() { // Format time SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss"); Date date = new Date(); String time = (date); return time; }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.