About the large amount of GridView data in Android, there is a lag when loading the GridView

Source: Internet
Author: User

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);}


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.