Segmented display and paging display of Android listview

Source: Internet
Author: User

Java code

Package COM. yangguangfu. listview; import android. app. listactivity; 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. abslistview. onscrolllistener; import android. widget. linearlayout. layoutparams;/***** @ author AFU **/public class mainactivity extends listactivity implements onscrolllistener {Private Static final string tag = "mainactivity"; private listviewadapter adapter = new listviewadapter (); private int lastitem = 0;/*** set the layout to be as big as the target. */private layoutparams wclayoutparams = new linearlayout. layoutparams (linearlayout. layoutparams. wrap_content, linearlayout. layoutparams. wrap_content);/*** sets the maximum layout display target */private layoutparams fflayoutparams = new linearlayout. layoutparams (linearlayout. layoutparams. fill_parent, linearlayout. layoutparams. fill_parent); Private progressbar; protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); log. I (TAG, "oncreate (bundle savedinstancestate)"); // linear layout linearlayout layout = new linearlayout (this); // sets the layout horizontal direction layout. setorientation (linearlayout. horizontal); // progress bar progressbar = new progressbar (this); // progress bar shows the position progressbar. setpadding (0, 0, 15, 0); layout. addview (progressbar, wclayoutparams); textview = new textview (this); textview. settext ("loading... "); textview. setgravity (gravity. center_vertical); layout. addview (textview, fflayoutparams); layout. setgravity (gravity. center); linearlayout loadinglayout = new linearlayout (this); loadinglayout. addview (layout, wclayoutparams); loadinglayout. setgravity (gravity. center); // get a listview to display the entry listview = getlistview (); // Add it to the footer page to display the listview. addfooterview (loadinglayout); // registerforcontextmenu (listview); // setlistadapter (adapter); listview. setonscrolllistener (this);} public void onscroll (abslistview V, int firstvisibleitem, int visibleitemcount, int totalitemcount) {lastitem = firstvisibleitem + visibleitemcount-1; system. out. println ("lastitem:" + lastitem); log. I (TAG, "lastitem:" + lastitem);} public void onscrollstatechanged (abslistview V, int state) {If (lastitem = adapter. count & State = onscrolllistener. scroll_state_idle) {adapter. count + = 10; adapter. yydatasetchanged (); log. I (TAG, "lastitem:" + lastitem) ;}/ *** use it to generate display data * @ author AFU **/class listviewadapter extends baseadapter {int COUNT = 10; public int getcount () {log. I (TAG, "Count:" + count); Return count;} public object getitem (INT POS) {log. I (TAG, "POS:" + POS); return Pos;} public long getitemid (INT POS) {return Pos;} public view getview (INT POs, view V, viewgroup p) {textview view = new textview (mainactivity. this); view. settext ("AFO player" + POS); log. I (TAG, "entry:" + POS); view. settextsize (20f); view. setheight (80); Return view ;}}}

Java code

Package COM. yangguangfu. listview; import android. app. listactivity; 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. button; import android. widget. linearlayout; import android. widget. listview; import android. widget. textview; import android. widget. linearlayout. layoutparams;/***** @ author AFU **/public class buttonloadingactivity extends listactivity {Private Static final string tag = "buttonloadingactivity"; private listviewadapter adapter = new listviewadapter (); /*** set the layout to show the target size */private layoutparams wclayoutparams = new linearlayout. layoutparams (linearlayout. layoutparams. wrap_content, linearlayout. layoutparams. wrap_content);/*** sets the maximum layout display target */private layoutparams fflayoutparams = new linearlayout. layoutparams (linearlayout. layoutparams. fill_parent, linearlayout. layoutparams. fill_parent); protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); log. I (TAG, "oncreate (bundle savedinstancestate):"); linearlayout layout = new linearlayout (this); layout. setorientation (linearlayout. horizontal); button = new button (this); button. settext ("click to load five items... "); button. setgravity (gravity. center_vertical); layout. addview (button, fflayoutparams); layout. setgravity (gravity. center); linearlayout loadinglayout = new linearlayout (this); loadinglayout. addview (layout, wclayoutparams); loadinglayout. setgravity (gravity. center); listview = getlistview (); listview. addfooterview (loadinglayout); button. setonclicklistener (New button. onclicklistener () {@ override public void onclick (view v) {adapter. count + = 5; log. I (TAG, "setonclicklistener:" + adapter. count); adapter. notifydatasetchanged () ;}}); setlistadapter (adapter) ;}public void onscrollstatechanged (abslistview V, int s) {log. I (TAG, "onscrollstatechanged (abslistview V, int s)");} class listviewadapter extends baseadapter {int COUNT = 10;/* 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) {textview = new textview (buttonloadingactivity. this); textview. setheight (80); textview. settextsize (20); textview. settext ("AFO player" + POS); log. I (TAG, "getview: pos:" + POS); return textview ;}}}

From: http://yangguangfu.iteye.com/blog/832809

 

 

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.