Android slide page

Source: Internet
Author: User

After analyzing the sliding paging effect on the internet, I thought the user experience was good and I simulated

 

Package com. My. activity;

Import com. My. R;
Import com. My. R. String;

Import Android. App. listactivity;
Import Android. OS. Bundle;
Import Android. OS. Handler;
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. progressbar;
Import Android. widget. textview;
Import Android. widget. abslistview. onscrolllistener;

/**
* ***** Sliding paging ******
* Implementation principle: by sliding your fingers, you can determine the data size and dynamically change the data. The loading at the bottom is a view.

*
* @ Author Owen
* @ 2010-8-17
* @ 09:29:07 AM
*/

Public class fenyelistactivity extends listactivity implements onscrolllistener {
Private Static final string tag = "*********** fenyelistactivity. Java *********";

Private itemadapter adapter;
Private int lastitem = 0;
Private int mprogressstatus = 0;
Private handler mhandler = new handler ();
Private progressbar;

@ Override
Protected void oncreate (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. oncreate (savedinstancestate );

Linearlayout searchlayout = new linearlayout (this );
// Linear Horizontal Layout
Searchlayout. setorientation (linearlayout. Horizontal );

// Add progress bars
Progressbar = new progressbar (this );
Progressbar. setpadding (0, 0, 15, 0 );
Searchlayout. addview (progressbar, new linearlayout. layoutparams (
Linearlayout. layoutparams. wrap_content,
Linearlayout. layoutparams. wrap_content ));

// Add text to set vertical center of Text
Textview = new textview (this );
Textview. settext (R. String. app_loading );
Textview. setgravity (gravity. center_vertical );
Searchlayout. addview (textview, new linearlayout. layoutparams (
Linearlayout. layoutparams. fill_parent,
Linearlayout. layoutparams. fill_parent ));

// Display both the progress bar and loaded text in the middle
Searchlayout. setgravity (gravity. center );

Linearlayout loadinglayout = new linearlayout (this );
Loadinglayout. addview (searchlayout, new linearlayout. layoutparams (
Linearlayout. layoutparams. wrap_content,
Linearlayout. layoutparams. wrap_content ));

Loadinglayout. setgravity (gravity. center );
// Load to the bottom of listactivity
Getlistview (). addfooterview (loadinglayout );

Registerforcontextmenu (getlistview ());

Adapter = new itemadapter ();
Setlistadapter (adapter );
Getlistview (). setonscrolllistener (this );
}

/**
* Firstvisbleitem: the first visible item
* Visibleitemcount: number of items visible
* Total totalitemcount count
* In the visible state of lastitem, the last item
*/
@ Override
Public void onscroll (abslistview view, int firstvisibleitem,
Int visibleitemcount, int totalitemcount ){
// Todo auto-generated method stub

Log. I (TAG, "firstvisibleitem =" + firstvisibleitem );
Log. I (TAG, "visibleitemcount =" + visibleitemcount );
Log. I (TAG, "totalitemcount =" + totalitemcount );

Lastitem = firstvisibleitem + visibleitemcount-1;
Log. I (TAG, "lastitem:" + lastitem );
}

/**
* If the view is rolling, this method will scroll the next frame before calling. In particular, it will call getview before calling
*/
@ Override
Public void onscrollstatechanged (abslistview view, int scrollstate ){
// Todo auto-generated method stub

If (lastitem = Adapter. Count & scrollstate = onscrolllistener. scroll_state_idle ){
Adapter. Count + = 10;
Adapter. notifydatasetchanged ();
}
}

Private class itemadapter extends baseadapter {

Int COUNT = 10;

@ Override
Public int getcount (){
// Todo auto-generated method stub
Return count;
}

@ Override
Public object getitem (INT position ){
// Todo auto-generated method stub
Return position;
}

@ Override
Public long getitemid (INT position ){
// Todo auto-generated method stub
Return position;
}

@ Override
Public View getview (INT position, view convertview, viewgroup parent ){
// Todo auto-generated method stub

Textview itemview = new textview (fenyelistactivity. This );

Itemview. settext ("item" + position );
Itemview. setheight (90 );

Return itemview;
}

}

}

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.