0

''' public class HomeFragment extends Fragment {

public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    View root   =inflater.inflate(android.R.layout.fragment_home,container,false)
    return root;
}

} '''

fragment_home created but not being recognized.

jj840
  • 1

2 Answers2

1

Try once-

  import packagename.R //import should be like this use your project package name 
    
           public class HomeFragment extends Fragment {
            
            public View onCreateView(@NonNull LayoutInflater inflater,
                                     ViewGroup container, Bundle savedInstanceState) {
                View root   =inflater.inflate(R.layout.fragment_home,container,false)**//Here must use R of project not a android default**
                return root;
            }
            }
Sandesh Khutal
  • 1,712
  • 1
  • 4
  • 17
  • Thanks bro this worked fine. The key was to import R and to add just R.layout.fragment_home,container,false and that worked. thanks again – jj840 May 16 '22 at 22:05
0

could you please be more specific about your issue
is the fragment not showing on the screen? or you want the naveController to recognize it and navigate to it in a certain action

remove the android directory and call R.layout.fragment_layout

 View root   =inflater.inflate(R.layout.fragment_home,container,false)
return root;
  • Thanks bro this worked after importing R "in this case R would be android object or the object created by us" ? – jj840 May 16 '22 at 22:10