A good solution is to load a certain amount of data first, and then at the bottom of the tip is loading!
Dynamic loading is the data that is put into adapter is loaded several times. When the user drags the GridView, a certain amount of data is loaded, similar to the Sina Weibo client.
Adding a Onscrolllistener listener event to the GridView will override the following two methods by default:
Here are a few examples:
<com.ui.widget.lazygridview xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/ GridView " android:layout_width=" fill_parent " android:layout_height=" fill_parent " android:gravity=" Center " android:horizontalspacing=" 10DP " android:listselector=" @android: Color/transparent " Android : numcolumns= "2" android:padding= "20DP" android:stretchmode= "columnWidth" android:verticalspacing= " 10DP "/>
Lazygridview:
/** * Scroll to the bottom auto Refresh * * @author Yinghui.hong * */public class Lazygridview extends GridView implements Onscrolllistener {Pub Lic Lazygridview (Context context) {super (context);} Public Lazygridview (context context, AttributeSet Attrs) {Super (context, attrs);} Public Lazygridview (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);} @Overridepublic void Onscroll (abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {}/** * list View scrolling */@Overridepublic void onscrollstatechanged (abslistview view, int scrollstate) {switch (scrollstate) {case ONSCROLLLISTENER.SCROLL_STATE_IDLE:LOG.V ("onscrollstatechanged", "Already stopped: Scroll_state_idle");//Judge Scroll to the bottom if ( View.getlastvisibleposition () = = (View.getcount ()-1)) {LOG.V ("onscrollstatechanged", "to the bottom.") Can request refresh ~~~~~~ "); if (listener! = null) {Listener.onscrollbottom ();}} Break;case onscrolllistener.scroll_state_fling:log.v ("onscrollstatechanged", "Start rolling: scroll_state_fling"); Case Onscrolllistener.scroll_staTE_TOUCH_SCROLL:LOG.V ("onscrollstatechanged", "Rolling: Scroll_state_touch_scroll"); Private Onscrollbottomlistener listener;public void Setonscrollbottomlistener (Onscrollbottomlistener listener) { This.setonscrolllistener (this); this.listener = listener;} public void Removeonscrollbottomlistener () {listener = null; System.out.println ("Removeonscrollbottomlistener");} /** * List View scroll to bottom listener * * @author Yinghui.hong * */public interface Onscrollbottomlistener {/** * list view scroll to bottom response */public voi D Onscrollbottom ();}}
Main activity:
@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( r.layout.activity_circle); Getactionbar (). Setdisplayhomeasupenabled (true); MBeans = new Arraylist<circleresbean > (); madapter = new Circleadapter (this, mBeans); GridView = (Lazygridview) Findviewbyid (R.id.gridview); Gridview.setadapter (Madapter); Gridview.setonscrollbottomlistener (this); Mpageindex = 0;queryjoinedcircles ( Mpageindex);}