Android source code: Android switching menu (Viewpager + Fragme), viewpagerfragme

Source: Internet
Author: User

Android source code: Android switching menu (Viewpager + Fragme), viewpagerfragme

Android switching menu (Viewpager + Fragme)

Supported platforms: Android runtime environment: Eclipse development language: Java

: Http://www.devstore.cn/code/info/245.html

Source code Introduction
Using Viewpager + Fragment to implement the top tab, you can slide and click to switch the Fragment page (if you need to add or reduce the page, modify PageSize-Add the Fragment to the Manager below)

Source code running



If I have resources on QQ, I can talk about it: 749099054


How to listen to button events in android viewpager, source code

Public class ViewPagerActor extends LinearLayout {
Private ViewPager viewPager;
Private MyAdapter myAdapter;
Private List <View> lists;
Public ViewPagerActor (Context context, AttributeSet attrs ){
Super (context, attrs );
LayoutInflater inflater = LayoutInflater. from (context );
Inflater. inflate (R. drawable. actor_viewpager_layout, this, true );
ViewPager = (ViewPager) findViewById (R. id. viewpager); // scroll the page
}

Public void setDates (List <View> lists ){
This. lists = lists;
}
Public void initDisplay (){
MyAdapter = new MyAdapter (lists );
ViewPager. setAdapter (myAdapter );
}
Public void notifyDataSetChanged (){
MyAdapter. notifyDataSetChanged ();
}

/**
* Set the page to display
* @ Param count
*/
Public void setCurrentItem (int count ){
ViewPager. setCurrentItem (count );
}

/**
* Add a page feed listener for viewPager
* @ Param onPageChangeListener
*/
Public void setOnPageChangeListener (OnPageChangeListener onPageChangeListener ){
ViewPager. setOnPageChangeListener (onPageChangeListener );
}

/**
* ViewPager fixed adapters inherit PagerAdapter
* @ Author Administrator
*
*/
Class MyAdapter extends PagerAdapter {
Private List <View> views;

Public MyAdapter (List <View> lists ){
This. views = lists;
}
@ Override
Public int getCount (){
Return views. size ();
}

@ Override
Public boolean isViewFromObject (View arg0, Object arg1 ){
Return arg0 = arg1;
}

@ Override
Public int getItemPosition (Object object ){
Return su ...... remaining full text>

How does Android ViewPager provide content in the control card on the Code side?

To control the content of ViewPager, the Adapter must be rewritten, which is similar to that of ListView;
ViewPager is a PageAdapter.
 

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.