top of page
Writer's pictureCodersarts AI

Fragment In Android | CodersArts

A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library, fragments are supported back to all relevant Android versions. Fragments encapsulate views and logic so that it is easier to reuse within activities.


Fragment basically use in navigation when we are wanted home page and User information page and tracking kind of things in a single page then we have to implement fragment


we have to create fragment activity for mutiple users






package com.example.app;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
publicclass MyAdapter extends FragmentPagerAdapter 
{
   privateContext myContext;
   int totalTabs;
   public MyAdapter(Contextcontext, FragmentManagerfm,  inttotalTabs) 
{
    super(fm);       
    myContext = context;this.totalTabs = totalTabs;    
}
@NonNull
@Overridepublic
Fragment getItem(intposition)
 {
switch (position)
 {
    case 0:
       BlankFragment blankFragment =newBlankFragment();
       return blankFragment;
    case1:      
          chat chat =new chat();
          return chat;
     case2: 
           home home =new home();
           return home;
      default:returnnull; 
       } 
   }
@Override
publicint getCount()
 {
     return totalTabs; 
   }
}

Hire an android developer to get quick help for all your android app development needs. with the hands-on android assignment help and android project help by Codersarts android expert. You can contact the android programming help expert any time; we will help you overcome all the issues and find the right solution.

Want to get help right now? Or Want to know price quote


Please send your requirement files at contact@codersarts.com. and you'll get instant reply as soon as requirement receives


6 views0 comments

Recent Posts

See All

Comments


bottom of page