Android: How to drag the gallery to prevent the gallery card from loading data immediately

Source: Internet
Author: User

One bad effect of gallery menu sliding is that each menu that goes through the middle is selected by default, and the data is loaded so that the switching is not smooth. There is a feeling of kakaka !! In fact, the thread is used to solve this problem. If the selected index value remains unchanged after a certain period of time, it indicates that it has remained stable. The last part.Code!
// ---------------------- Used constant -----------------------------
Private int showingindex =-1;
Private Static final int time_out_display = 300;
Private int toshowindex = 0;
//--------------------------------------------------
// Process the selected event
Public void onitemselected (adapterview <?> Parent, view V, final int position,
Long ID ){

//--------------------------------------------------
Toshowindex = position;
Final handler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
If (showingindex! = Toshowindex ){
Showingindex = toshowindex;
Menu_position = position;

// Process your business logic
}
}
};
Thread checkchange = new thread (){
@ Override
Public void run (){
Int myindex = toshowindex;
Try {
Sleep (time_out_display );
If (myindex = toshowindex ){
Handler. sendemptymessage (0 );
}
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}
};

Checkchange. Start ();

}
OK, so that you can smoothly slide your components !! Basically, one card and one card won't happen!

Combined with titlegall. setcallbackduringfling (false);, you can create a sliding navigation bar at the top or bottom.

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.