Android is based on ListView to implement a similar market paging load effect sample _android

Source: Internet
Author: User
Tags stub

This article illustrates the Android based ListView implementation of a similar market paging load effect. Share to everyone for your reference, specific as follows:

In recent days research ListView implementation of paging load and rolling load, found that can be implemented using the ListView Onscroll method, directly on the code

Listviewscroll.java

Package zy.lucifer.ListViewScroll;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.AbsListView;
Import Android.widget.BaseAdapter;
Import Android.widget.LinearLayout;
Import Android.widget.ListView;
Import Android.widget.ProgressBar;
Import Android.widget.TextView;
Import Android.widget.Toast;
Import Android.widget.AbsListView.OnScrollListener;
Import Android.widget.LinearLayout.LayoutParams; The public class Listviewscroll extends activity {/** called the ' when the ' is the ' is ' the ' activity ' is a-created private layoutparams Mlayoutparams = new Linearlayout.layoutparams (LinearLayout.LayoutParams.WRAP_CONTENT, Linearlayout.layoutpara Ms.
  Wrap_content); /** * Set layout display target Maximization property/private Layoutparams fflayoutparams = new Linearlayout.layoutparams (linearlayout.lay
  Outparams.fill_parent, LinearLayout.LayoutParams.FILL_PARENT); ListviEW ListView;
  private int lastitem = 0;
  LinearLayout loadinglayout;
  Private Listviewadapter adapter;
    @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Setcontentview (R.layout.main);
    ListView = (ListView) Findviewbyid (r.id.mylist); LOG.I ("Test", "OnCreate (Bundle savedinstancestate) >>>>>>>>>>>>>>>")
    ;
    Linear layout LinearLayout layout = new LinearLayout (this);
    Set the horizontal direction of the layout layout.setorientation (linearlayout.horizontal);
    progress bar ProgressBar ProgressBar = new ProgressBar (this);
    The progress bar shows the position progressbar.setpadding (0, 0, 15, 0);
    Add the progress bar to the layout Layout.addview (ProgressBar, mlayoutparams);
    Text content TextView TextView = new TextView (this);
    Textview.settext ("Load ...");
    Textview.setgravity (gravity.center_vertical);
    Add the text to the layout Layout.addview (TextView, fflayoutparams); Set the gravity direction of the layout, that is, the alignment is layout.setgravity (gravity.
    CENTER);
    Set ListView Footer Layout loadinglayout = new LinearLayout (this);
    Loadinglayout.addview (layout, mlayoutparams);
    Loadinglayout.setgravity (Gravity.center);
    Listview.addfooterview (loadinglayout);
    adapter = new Listviewadapter ();
    Listview.setadapter (adapter); Listview.setonscrolllistener (New Onscrolllistener () {@Override public void onscroll (abslistview view, int fir Stvisibleitem, int visibleitemcount, int totalitemcount) {//TODO auto-generated method stub Lo G.I ("Test", "Scroll>>>first:" + Firstvisibleitem + ", Visible:" + VisibleItemCount + ", total:" + Totalitemco
        UNT);
        LastItem = Firstvisibleitem + visibleItemCount-1;
        LOG.I ("Test", "Scroll>>>lastitem:" + LastItem);
        Display 50 ListItem, 0-49, because the onscroll is triggered after the "slide" has been executed, so use adapter.count<=41 as the condition int scrolllength=101; if (adapter.count<=scrolllength) {if (firstvisibleitem+visibleitemcount==Totalitemcount) {adapter.count = 10;
            Adapter.notifydatasetchanged ();
            Listview.setselection (LastItem);
            int CURRENTPAGE=ADAPTER.COUNT/10;
          Toast.maketext (Getapplicationcontext (), "+currentpage+", "page", Toast.length_long). Show ();
        } else {Listview.removefooterview (loadinglayout); @Override public void onscrollstatechanged (Abslistview view, int scrollstate) {//TODO Auto
  -generated method stub}});
      Class Listviewadapter extends Baseadapter {int count = * Starting amount/public int getcount () {
    return count;
    Public Object getitem (int pos) {return pos;
    public long Getitemid (int pos) {return pos;
      Public View getview (int pos, View V, ViewGroup p) {log.i ("test", "Getview>>>pos:" + pos);
      TextView view; if (v = = null) {view = new TextView (LISTVIewscroll.this);
      else {view = (TextView) v;
      } view.settext ("ListItem" + pos);
      View.settextsize (20f);
      View.setgravity (Gravity.center);
      View.setheight (60);
    return view;

 }
  }
}

Main.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
  android:orientation=" vertical "
  android:layout_width=" fill_parent "
  android:layout_" height= "Fill_parent"
  >
<listview android:cachecolorhint= "#00000000" android:id= "@+id/mylist
" Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent"
    >
  </ListView>
< /linearlayout>

For more information on Android-related content readers can view the site: "Android View tips Summary", "Android Layout Layout Skills Summary", "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course" , Android Debugging tips and FAQ Solutions Summary, Android Multimedia tips summary (audio, video, audio, etc.), "Android Basic Components Usage Summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.