Android Learning--click Actionbar to implement the ListView to return to the top of

Source: Internet
Author: User

Do not know when you brush the microblog, have encountered, refresh too much, want to return to the top of the microblog before the situation. In fact, clicking on the top of the Actionbar can return to the top. Instead of always pulling down.

Don't say much, talk about how to do this in Android.

First, add a customview to Actionbar.

CustomView Layout file Actionbar_layout.xml:

1<?XML version= "1.0" encoding= "Utf-8"?> 2<LinearLayoutXmlns:android="Http://schemas.android.com/apk/res/android"3Android:id="@+id/ll_topbar"4Android:layout_width="Match_parent"5android:layout_height="Wrap_content"6android:orientation= "vertical" > 7 8 <textview 9 android:layout_width= "wrap_content" 10 android:layout_height=" Wrap_content " 11 android:layout_gravity= "center" 12 android:textcolor= "#000000" 13 android:id= "@+id/mytext" 14 android:textsize= "18SP"/>15 + </LINEARLAYOUT>       

Then set Actionbar or load Custiomview to

1 ActionBar ActionBar = Getactionbar (); 2 actionbar.setdisplayoptions (Actionbar.display_show_custom); 3 Actionbar.setcustomview (r.layout.actionbar_layout);
1   View CustomView = layoutinflater.  From (new LinearLayout (false);  2 Getactionbar (). setdisplayshowcustomenabled (3 Getactionbar (). Setcustomview (CustomView);    

Finally, add the onclick event to Custiomview to enable the ListView to return to the top logic:

1   if (!mlistview.isstackfrombottom ()) {2           Mlistview.setstackfrombottom (TRUE); 3   }4     Mlistview.setstackfrombottom (false);


Http://www.tuicool.com/articles/6jEVze3

Android Learning--click Actionbar to implement the ListView to return to the top of

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.