Can't convert taba to fragment)

Source: Internet
Author: User

Can't convert taba to fragment)

 

When creating a new android project, use the tabbed activity template to automatically configure viewpager.

In
@ Override
Public Fragment getItem (int position ){
// GetItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// Below ).


Return PlaceholderFragment. newInstance (position + 1 );
}
Changed:


@ Override
Public Fragment getItem (int position ){
// GetItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// Below ).


Switch (position ){
Case 0:
Return new taba ();



Case 1:
Return new tabb ();

Case 2:
Return new tabc ();

Default:
// This page does not exists
Return null;
}
// Return PlaceholderFragment. newInstance (position + 1 );
}


And create three taba. java tabb. java tabc. java, such

Public class taba extends Fragment {



@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){




View rootView = inflater. inflate (R. layout. fragment_a, container,
False );
Return rootView;
}


}


And the corresponding layout xml, such
Xmlns: tools = http://schemas.android.com/tools
Android: layout_width = match_parent
Android: layout_height = match_parent
Android: paddingBottom = @ dimen/activity_vertical_margin
Android: paddingLeft = @ dimen/activity_horizontal_margin
Android: paddingRight = @ dimen/activity_horizontal_margin
Android: paddingTop = @ dimen/activity_vertical_margin
Tools: context = com. example. samepledemo. taba>



Android: id = @ + id/section_label
Android: layout_width = wrap_content
Android: layout_height = wrap_content
Android: text = taba/>






In fact, there are many websites, especially stackoverflow.
In fact, I wrote this mainly because I encountered some strange problems in the next step. I am preparing to open android studio for comparison.
Find the cause.
In the getitem method java file, import android. support. v4.app. Fragment is used;
In taba. java
Import android. app. Fragment;
So, change all
Import android. support. v4.app. Fragment;
That's all.


Import android. support. v4.app. Fragment; and import android. app. Fragment; the main differences are:

Android. support. v4.app. Fragment supports android as low as android 1.6, and android. app. Fragment supports android as low as 3.0.

 

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.