I have Fragment with layout of CoordinatorLayout Inside with NestedScrollView and inside nestedscrollview i have ViewPager and TabLayout with fragments. Tabs is visible but fragment related to tabs is not loading.
Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:background="?android:attr/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--app:contentScrim="?attr/colorPrimary" -->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ViewPagerImages"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
android:scrollIndicators="top|right">
</android.support.v4.view.ViewPager>
<ProgressBar
android:layout_width="120dp"
android:layout_height="120dp"
android:id="#+id/Progress_Bar_Image"
android:layout_gravity="center_horizontal|center_vertical"
android:visibility="visible"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right|top"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp"
android:background="#drawable/round_default"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="/5"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="bottom"
android:padding="15dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unsa"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="#+id/user_S"
android:layout_width="25dp"
android:layout_height="25dp"
android:padding="10dp" />
<TextView
android:id="#+id/ViewPager_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_behavior="com.boysjoys.com.pro_working1.CustomClass.UserProfile_Behaviour"
android:textSize="35sp" />
<TextView
android:id="#+id/ViewPager_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Age"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="New Delhi"
android:layout_below="#id/unsa"
android:layout_marginLeft="37dp"
android:id="#+id/ViewPager_City"
/>
<Button
android:id="#+id/Attached"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/round_button"
android:layout_alignParentBottom="true"
android:elevation="14dp"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:text="WRITE ME"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
<View
android:id="#+id/fabBGLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/custom_transparent_color1"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabOne"
android:layout_gravity="bottom|end"
android:padding="12dp"
android:visibility="gone"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabTwo"
android:padding="12dp"
app:fabSize="mini"
android:visibility="gone"
android:layout_gravity="bottom|end"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabThree"
android:layout_gravity="bottom|end"
android:padding="12dp"
app:fabSize="mini"
android:visibility="gone"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMain"
android:padding="12dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:src="#drawable/com_facebook_tooltip_black_xout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
// NESTED SCROLL VIEW WHERE THE PROBLEM ARISE
// TABLAYOUT IS VISIBLE BUT FRAGMENT IS NOT.
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/userProfile_NestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="13dp"
android:background="#android:color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollViewChild"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="15dp">
<!--To show tab on top of view pager-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#color/place_autocomplete_prediction_primary_text_highlight"
app:tabSelectedTextColor="#color/colorPrimary"
app:tabIndicatorColor="#color/colorPrimary"
android:id="#+id/userProfile_Viewpager_Tab">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/userProfile_Viewpager_Tab"
android:id="#+id/userProfile_Viewpager_ViewPager">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
ViewPager Adapter
public class UserProfile_TabAdapter extends FragmentPagerAdapter {
String TAG = "###TabAdapter###";
Context context;
public UserProfile_TabAdapter(FragmentManager fm,Context context) {
super(fm);
this.context=context;
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
Log.d(TAG," Positions "+position);
switch (position) {
case 0:
fragment = Fragment.instantiate(context,Info_fragment.class.getName());
break;
case 1:
Log.d(TAG, "User Photos Running");
fragment = Fragment.instantiate(context,Photo_fragment.class.getName());
break;
case 2:
Log.d(TAG, "User Connections Running");
fragment = Fragment.instantiate(context,Connections_fragment.class.getName());
break;
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "About";
case 1:
return "Photo";
case 2:
return "Connections";
}
return null;
}
}
Fragment Where i try to load fragment into viewpager
//NESTED SCROLL VIEW TAB LAYOUT AND VIEW PAGER
userInfo_ViewPager=(ViewPager) view.findViewById(R.id.userProfile_Viewpager_ViewPager);
UserProfile_TabAdapter userProfile_tabAdapter=new UserProfile_TabAdapter(getChildFragmentManager(),getActivity());
userInfo_ViewPager.setAdapter(userProfile_tabAdapter);
tabLayout=(TabLayout) view.findViewById(R.id.userProfile_Viewpager_Tab);
tabLayout.setupWithViewPager(userInfo_ViewPager);
Fragment to load into viewpager
public class Info_fragment extends Fragment {
public static final String TAG="### INFO ####";
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.userprofile_photos,container,false);
//Above Layout only have colorful background to match parent.
return view;
}
}
Try this
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);
Add This Line in your in NestedScrollView
android:fillViewport="true"
// your appBar layout height is match_parent change it with wrap_content
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
The problem is your view pager height. Just make some height then your page will be visible.
Example:
<android.support.v4.view.ViewPager
android:id="#+id/userProfile_Viewpager_ViewPager"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_below="#id/userProfile_Viewpager_Tab">
</android.support.v4.view.ViewPager>
You have to find the solution why the view pager not taken the height
or
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);
I have same issue and the best solution is to set hight for your viewpager
Example:
android:layout_height="500dp"
Related
i just want to replace a fragment by using this code:
fragmentManager.beginTransaction()
.replace(R.id.homepage_fragment_menu, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
the fragment has recyclerview. but when i see the result of fragment, there's no shown of recyclerview. but when i checked in LayoutInspector, it's showed, but invisible like
this
And here's the code when set the adapter on RecyclerView
bookingHistoryProgressBar.setVisibility(View.GONE);
bookingHistoryList.setVisibility(View.VISIBLE);
adapterBookingHistoryList = new AdapterBookingHistoryList(this, bookingHistoryListModels);
bookingHistoryList.setAdapter(adapterBookingHistoryList);
Here's the layout code for RecyclerView and Adapter
XML Fragment Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grey"
tools:context=".home.bookinghistorypage.BookingHistoryFragment"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="#+id/bookingHistory_listBooking"
android:background="#color/white_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/booking_history_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginBottom="#dimen/margin_small"
app:cardUseCompatPadding="true">
<LinearLayout
android:background="#color/white"
android:paddingLeft="#dimen/padding_large"
android:paddingRight="#dimen/padding_large"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_name"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="3dp"
android:textColor="#color/black"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_code"
android:gravity="end"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:textColor="#color/grey_2"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_status"
android:background="#color/lightOrange"
android:textColor="#color/black"
android:textSize="#dimen/text_very_small"
android:paddingLeft="#dimen/padding_small"
android:paddingRight="#dimen/padding_small"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:layout_marginBottom="#dimen/padding_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_marginBottom="#dimen/padding_medium"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_tanggal"
android:layout_width="20dp"
android:layout_height="20dp" />
<helper.CustomFontMontserratRegularTextView
android:visibility="gone"
android:id="#+id/booking_history_day_booked"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_actual_date"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_time_booked"
android:layout_marginStart="#dimen/margin_medium"
android:layout_marginLeft="#dimen/margin_medium"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
XML Activity (Parent of Fragment)
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottomsheet"
android:background="#color/black_image_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_title_and_description"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/homepage_fragment_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar_layout"
android:layout_above="#id/navigation"
/>
<include
android:id="#+id/navigation"
layout="#layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ProgressBar
android:id="#+id/homepage_progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
</com.flipboard.bottomsheet.BottomSheetLayout>
AdapterJava
#NonNull
#Override
public BookingHistoryListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.adapter_booking_history,parent,false);
context = parent.getContext();
return new BookingHistoryListViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final BookingHistoryListViewHolder holder, final int position) {
String data = GetDateUtils.convertEpochToDate(dataList.get(position).getActualDate());
if(dataList.get(position).getBookingStatus().equals("Completed") && dataList.get(position).getFlagRating().equals(false)){
Intent intent = new Intent(holder.itemView.getContext(), ProfessionalRatingActivity.class);
intent.putExtra("professionalId", dataList.get(position).getProfessionalId());
intent.putExtra("expertiseId", dataList.get(position).getExpertiseId());
intent.putExtra("professionalName",dataList.get(position).getProfessionalName());
holder.itemView.getContext().startActivity(intent);
}
if(dataList.get(position).getBookingStatus().equals("OnProcess")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.on_process));
}else if(dataList.get(position).getBookingStatus().equals("Cancel")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.cancelled));
}else if(dataList.get(position).getBookingStatus().equals("Completed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.completed));
}else if(dataList.get(position).getBookingStatus().equals("Reserved")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.reserved));
}else if(dataList.get(position).getBookingStatus().equals("Reschedule")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.rescheduled));
}else if(dataList.get(position).getBookingStatus().equals("Confirmed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.confirmed));
}
holder.bookingHistoryName.setText(dataList.get(position).getProfessionalName());
holder.bookingHistoryStatus.setText(dataList.get(position).getBookingStatus());
holder.bookingHistoryDayBooked.setText(dataList.get(position).getDayBooked());
holder.bookingHistoryCode.setText(String.format(Locale.getDefault(),"ID: %s",dataList.get(position).getCode()));
holder.bookingHistoryActualDate.setText(String.format(Locale.getDefault(),"%s",data));
holder.bookingHistoryTimeBooked.setText(String.format(Locale.getDefault(),"# %s",dataList.get(position).getTimeBooked()));
holder.bookingHistoryCardview.setOnClickListener(v -> {
Intent intent = new Intent(v.getContext(), BookingHistoryDetailActivity.class);
intent.putExtra("idProfessionalAdapter", dataList.get(position).getId());
holder.itemView.getContext().startActivity(intent);
});
}
#Override
public int getItemCount() {
return dataList!=null ? dataList.size() :0 ;
}
You're nesting your fragment view in a BottomSheetLayout, and according to the source code, the initial visibility is View.INVISIBLE:
private void init() {
// ...
dimView = new View(getContext()); // Line 150
dimView.setBackgroundColor(Color.BLACK);
dimView.setAlpha(0);
dimView.setVisibility(INVISIBLE);
// ...
}
public void setContentView(View contentView) {
super.addView(contentView, -1, generateDefaultLayoutParams());
super.addView(dimView, -1, generateDefaultLayoutParams());
}
I'm not familiar with Flipboard library, but I've got a feeling that you might be using it incorrectly. Maybe try:
bottomSheetLayout.showWithSheetView(...)
Or please check on their GitHub for usage.
Your recycler view in xml layout has `android:visibility="gone". Remove this line or change it to visible.
This is what my nestedscrollview looks like
This is where my viewpager, along with other views and layouts are placed inside that nestedscrollview
Now issue is that the viewpager, which is swiping fragments of recyclerviews left and right, is not scrolling down along with the nestedscrollview. Activity scrolls only upto the tab layout, as shown in the second picture. Viewpager scrolls nested. Can you PLEASE solve this problem?
This is how my main activity's layout looks like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:id="#+id/main_profile"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="#+id/app_bar"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/profile_image"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="#drawable/sample_image"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="William Stevenson"
android:textSize="24sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="#+id/userName" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Graphic Designer. Freelancer"
android:textSize="16sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:layout_below="#id/userName"
android:id="#+id/tagline"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="#id/tagline"
android:layout_marginTop="48dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="48dp"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:textSize="12sp"
android:textColor="#f0f0f0"
android:text="Follow"
android:layout_centerHorizontal="true"
android:id="#+id/follow"
android:background="#drawable/follow_button_flat"/>
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="#id/follow"
android:layout_centerVertical="true"
android:id="#+id/voiceCallMessage"
android:src="#drawable/ic_mic_none_white_48dp"
android:layout_marginRight="32dp" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toRightOf="#id/follow"
android:layout_centerVertical="true"
android:id="#+id/videoCallMessage"
android:layout_marginLeft="32dp"
android:src="#drawable/ic_videocam_white_48dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:rippleColor="#303030"
app:backgroundTint="#3292D3"
app:layout_anchor="#id/app_bar"
android:src="#drawable/ic_bubble_chart_white_48dp"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/nestedScrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:id="#+id/profileStats"
android:orientation="horizontal">
...
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:id="#+id/imagesAndVideos"
android:layout_below="#id/profileStats">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/frame_layout_corner"
android:clickable="false">
...
</TableLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="800+ Images"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="#+id/imagesTag"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="32dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="Show All"
android:gravity="center"
android:id="#+id/showAll"
android:background="#drawable/follow_button_flat"
android:textColor="#f0f0f0"
android:textSize="14sp"/>
</LinearLayout>
</FrameLayout>
<com.gigamole.navigationtabstrip.NavigationTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
app:nts_animation_duration="300"
app:nts_factor="1.2"
app:nts_size="16dp"
app:nts_type="line"
app:nts_titles="#array/posts_and_friends"
android:layout_below="#id/imagesAndVideos"
android:layout_marginTop="48dp"
android:id="#+id/post_and_friends_nav_strip"/>
<!--Problem is here-->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/posts_friends_view_pager"
android:layout_below="#id/post_and_friends_nav_strip"
android:layout_marginTop="16dp"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
This is what my both the fragments looks like:
Fragment 1's layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainPosts"
android:layout_height="wrap_content"/>
Fragment 2's layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/friends"
android:layout_height="wrap_content"/>
Yeah, almost similar.
Edit: I've tried setting android:nestedScrollingEnabled to false in the recyclerview. But It just stops scrolling of the viewpager. Activity can't be scrolled down below the tab layout of the viewpager. Viewpager remains below the phone screen.
Edit 2: This is what my main activity looks like:
public class Profile extends AppCompatActivity {
TextView userName, tagline, followers, followersTag, points, pointsTag, following, followingTag, imagesTag;
ImageView userImage, sample1, sample2, sample3, sample4;
Button showAllImages;
Typeface robotoRegular, robotoLight;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_profile);
initActivity();
ViewPager postsAndFriendsViewPager = (ViewPager) findViewById(R.id.posts_friends_view_pager);
FragmentManager fragmentManager = getSupportFragmentManager();
ViewPagerAdapterPostsFriends viewPagerAdapterPostsFriends = new ViewPagerAdapterPostsFriends(fragmentManager);
postsAndFriendsViewPager.setAdapter(viewPagerAdapterPostsFriends);
NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.post_and_friends_nav_strip);
navigationTabStrip.setTabIndex(0);
navigationTabStrip.setStripColor(Color.TRANSPARENT);
navigationTabStrip.setActiveColor(Color.RED);
navigationTabStrip.setInactiveColor(Color.DKGRAY);
navigationTabStrip.setViewPager(postsAndFriendsViewPager);
}
class ViewPagerAdapterPostsFriends extends FragmentStatePagerAdapter
{
ViewPagerAdapterPostsFriends(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if(position == 0)
return Posts.init();
return ProfileFriends.init();
}
#Override
public int getCount() {
return 2;
}
}
private void initActivity()
{
userImage = (ImageView) findViewById(R.id.profile_image);
sample1 = (ImageView) findViewById(R.id.sample1);
sample2 = (ImageView) findViewById(R.id.sample2);
sample3 = (ImageView) findViewById(R.id.sample3);
sample4 = (ImageView) findViewById(R.id.sample4);
userName = (TextView) findViewById(R.id.userName);
imagesTag = (TextView) findViewById(R.id.imagesTag);
tagline = (TextView) findViewById(R.id.tagline);
points = (TextView) findViewById(R.id.points);
pointsTag = (TextView) findViewById(R.id.pointsTag);
followers = (TextView) findViewById(R.id.followers);
followersTag = (TextView) findViewById(R.id.followersTag);
following = (TextView) findViewById(R.id.following);
followingTag = (TextView) findViewById(R.id.followingTag);
showAllImages = (Button) findViewById(R.id.showAll);
robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
robotoRegular = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
Picasso.with(this).load(R.drawable.sample_image).transform(new BrightnessFilterTransformation(this, -0.1f)).into(userImage);
userName.setTypeface(robotoLight);
imagesTag.setTypeface(robotoLight);
tagline.setTypeface(robotoLight);
points.setTypeface(robotoRegular);
pointsTag.setTypeface(robotoRegular);
followers.setTypeface(robotoRegular);
followersTag.setTypeface(robotoRegular);
following.setTypeface(robotoRegular);
followingTag.setTypeface(robotoRegular);
showAllImages.setTypeface(robotoLight);
}
}
Trying to push TextViews to the bottom of the ViewPager container. Right now the TextViews only stay on the top, both when I wrap_content and match_parent. Here's the XML:
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_above="#+id/layout_view_pager_navigation">
<TextView
android:id="#+id/string_main_intro_1"
android:text="#string/string_main_intro_1"
android:background="#color/buttonColor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/textPrimary"
android:textSize="22sp"
android:textAlignment="center"
android:gravity="bottom"/>
<TextView
android:id="#+id/string_main_intro_2"
android:text="#string/string_main_intro_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/textPrimary"
android:textSize="22sp"
android:textAlignment="center"
android:gravity="bottom"/>
<TextView
android:id="#+id/string_main_intro_3"
android:text="#string/string_main_intro_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/textPrimary"
android:textSize="18sp"
android:textAlignment="center"
android:gravity="bottom"/>
<TextView
android:id="#+id/string_main_intro_4"
android:text="#string/string_main_intro_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/textPrimary"
android:textSize="18sp"
android:textAlignment="center"
android:gravity="bottom"/>
</android.support.v4.view.ViewPager>
I would suggest creating a different layout for your TextViews like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/my_tvs"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
>
<TextView
android:id="#+id/string_main_intro_1"
android:text="#string/string_main_intro_1"
android:background="#color/buttonColor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textPrimary"
android:textSize="22sp"
android:textAlignment="center"
/>
<TextView
android:id="#+id/string_main_intro_2"
android:layout_below="#+id/string_main_intro_1"
android:text="#string/string_main_intro_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textPrimary"
android:textSize="22sp"
android:textAlignment="center"
/>
<TextView
android:id="#+id/string_main_intro_3"
android:layout_below="#+id/string_main_intro_2"
android:text="#string/string_main_intro_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textPrimary"
android:textSize="18sp"
android:textAlignment="center"
/>
<TextView
android:id="#+id/string_main_intro_4"
android:layout_below="#+id/string_main_intro_3"
android:text="#string/string_main_intro_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textPrimary"
android:textSize="18sp"
android:textAlignment="center"
/>
</RelativeLayout>
Then your ViewPager layout would look like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_above="#+id/layout_view_pager_navigation">
</RelativeLayout>
Then in your Viewpager.java you can add the views:
ViewPager vpp = (ViewPager) findViewById(R.id.pager);
this.addPages(vpp);
RelativeLayout relative = (RelativeLayout) findViewById(R.id.my_tvs);
relative.setGravity(RelativeLayout.ALIGN_BOTTOM);
//ADD ALL PAGES TO TABLAYOUT
private void addPages(ViewPager pager){
MyFragPagerAdapter adapter=new
MyFragPagerAdapter(getSupportFragmentManager());
adapter.addPage(new MyCustomView()); <----------- This will be the layout with your textViews
You will also need a adapter to add the views--
public class MyFragPagerAdapter extends FragmentPagerAdapter {
ArrayList<Fragment> pages=new ArrayList<>();
public MyFragPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return pages.get(position);
}
#Override
public int getCount() {
return pages.size();
}
//ADD A PAGE
public void addPage (Fragment f){
pages.add(f);
}
//SET TITLE FOR TAB
#Override
public CharSequence getPageTitle(int position) {
return pages.get(position).toString();
}
}
This is my Layout where I add Tablayout and ViewPager inside the ScrollView .
EveryThing is ok , but viewPager fragment doesn't show anything .
This is My xml Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#252525"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/poster"
android:layout_width="96dp"
android:layout_height="128dp"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:background="#eee"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txt_onvan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/poster"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="عنوان" />
<TextView
android:id="#+id/txt_sazande"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_onvan"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="سازنده" />
<TextView
android:id="#+id/txt_nazar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_sazande"
android:layout_toLeftOf="#id/poster"
android:text="تعداد نظر" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/poster" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And This is my ViewPager Adapter :
package ir.dink.cordinatorexample;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PagerAdapter extends FragmentStatePagerAdapter {
//============================================ Constructor
public PagerAdapter(FragmentManager fm) {
super(fm);
}
//============================================ GetItem Method ()
#Override
public Fragment getItem(int position) {
Fragment frag = null;
switch (position) {
case 0:
frag = new FragmentOne();
break;
case 1:
frag = new FragmnentTwo();
break;
}
return frag;
}
//============================================= GetCount Method ()
#Override
public int getCount() {
return 2;
}
//============================================= GetPageTitle
#Override
public CharSequence getPageTitle(int position) {
String title = "";
switch (position) {
case 0:
title = "First";
break;
case 1:
title = "Second";
break;
}
return title;
}
}
And This is Screen Shot from That :
You should add android:fillViewport="true" to your ScrollView.
like This :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#252525"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/poster"
android:layout_width="96dp"
android:layout_height="128dp"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:background="#eee"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txt_onvan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/poster"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="عنوان" />
<TextView
android:id="#+id/txt_sazande"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_onvan"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="سازنده" />
<TextView
android:id="#+id/txt_nazar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_sazande"
android:layout_toLeftOf="#id/poster"
android:text="تعداد نظر" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/poster" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
and You can see the this link too .
I have an Activity that have an appBarLayout with a TabLayout that should cover the 2/5 of the screen, so it's a big AppBarLayout. I created it, made the tabLayout and configured the viewPager and it is working, but there are three with issues that I can't figure out how to resolve:
Without this app:layout_behavior="#string/appbar_scrolling_view_behavior" the viewpager shows beside the appBarLayout
Whenever I enter in any of the editTexts the AppBarLayout shows fullscreen.
The second fragment has big height and should scroll down, but the it doesn't.
Relevant code:
Activity with the appBarLayout and the viewPager
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/rootLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
>
<TextView
android:id="#+id/title"
android:textSize="17sp"
android:text="#string/app_name"
android:textColor="#color/green_900"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
<ImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="#drawable/logo_home"
android:fitsSystemWindows="true"
/>
<TextView
android:id="#+id/txt_version"
android:text="#string/app_version"
android:textColor="#color/white"
android:textSize="10sp"
android:layout_below="#+id/img_logo"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabMode="fixed"
app:layout_collapseMode="pin"
app:tabIndicatorHeight="3dp"
app:tabIndicatorColor="#color/light_green_a700"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white_background" />
</android.support.design.widget.CoordinatorLayout>
The second page (Tab) that should scroll:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/white_background"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="23dp"
android:background="#color/white_background">
<Button
android:id="#+id/btn_facebook_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/facebook_register"
android:drawableLeft="#drawable/fb_logo"
android:textSize="15sp"
android:padding="5dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:textColor="#color/white"
android:background="#drawable/button_facebook_shape"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_marginTop="20dp"
android:id="#+id/white_line"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="0.5dp"/>
<View
android:background="#color/login_hint"
android:layout_width="match_parent"
android:layout_below="#+id/white_line"
android:layout_height="0.5dp"/>
<TextView
android:layout_marginTop="20dp"
android:textColor="#color/login_hint"
android:background="#color/white_background"
android:layout_width="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="o con tu mail..."/>
</RelativeLayout>
<EditText
android:id="#+id/edt_register_name"
android:layout_width="match_parent"
android:background="#drawable/edit_text_shape"
android:padding="20dp"
android:textSize="15sp"
android:maxLines="1"
android:inputType="textCapWords"
android:imeOptions="actionNext"
android:textColorHint="#color/login_hint"
android:hint="#string/txt_register_name"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edt_register_lastname"
android:layout_marginTop="15dp"
android:padding="20dp"
android:textSize="15sp"
android:maxLines="1"
android:inputType="textCapWords"
android:imeOptions="actionNext"
android:background="#drawable/edit_text_shape"
android:layout_width="match_parent"
android:textColorHint="#color/login_hint"
android:hint="#string/txt_register_last_name"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edt_register_email"
android:layout_marginTop="15dp"
android:padding="20dp"
android:textSize="15sp"
android:maxLines="1"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:background="#drawable/edit_text_shape"
android:layout_width="match_parent"
android:textColorHint="#color/login_hint"
android:hint="#string/txt_register_email"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edt_register_pass"
android:layout_marginTop="15dp"
android:padding="20dp"
android:textSize="15sp"
android:maxLines="1"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:background="#drawable/edit_text_shape"
android:layout_width="match_parent"
android:textColorHint="#color/login_hint"
android:hint="#string/txt_register_pass"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/edt_register_pss_conf"
android:layout_marginTop="15dp"
android:padding="20dp"
android:textSize="15sp"
android:maxLines="1"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:background="#drawable/edit_text_shape"
android:layout_width="match_parent"
android:textColorHint="#color/login_hint"
android:hint="#string/txt_register_pass_confirm"
android:layout_height="wrap_content" />
<Button
android:layout_marginTop="15dp"
android:id="#+id/btn_register_done"
android:text="#string/btn_register_done"
android:drawableLeft="#drawable/kick"
android:paddingLeft="30dp"
android:textColor="#color/white"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/button_done_shape"/>
</LinearLayout>
</ScrollView>
The java code for the Activity and the viewPager
public class LoginRegisterActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new myFragmentPagerAdapter(getSupportFragmentManager(), LoginRegisterActivity.this));
TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
}
public class myFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 2;
private String tabTitles[] = new String[]{"Ingresar", "Registrarse"};
private Context context;
public myFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return LoginFragment.newInstance(position);
case 1:
return RegisterFragment.newInstance(position);
default:
return null;
}
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}