-3

Before i begin,let me say that i've already checked all the links regarding this and the inflater init method doesn't work for me unfortunately

Fragment.java

 public View onCreateView(LayoutInflater inflater1, ViewGroup container, Bundle savedInstanceState) {
   View view = inflater1.inflate(R.layout.tab, container, false);
    context = getActivity();
    findViews(view);
    setBar();
    setPie();
    return view;//inflater1.inflate(R.layout.tab, container, false);

}

 private void findViews(View view) {
    inflater=LayoutInflater.from(context);
    root=(ViewGroup)view.findViewById(R.id.root);
   piechart= (PieChart)view.findViewById(R.id.pie_chart);
    barChart = (BarChart)view.findViewById(R.id.barchart);
    popupContentView=inflater.inflate(popupdashboard,root,false);

Activity.java

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard2);
    //Initializing viewPager
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    tabLayout.setSelectedTabIndicatorColor(Color.MAGENTA);
    //Adding the tabs using addTab() method
    tabLayout.addTab(tabLayout.newTab().setText("Dashboard"));
    tabLayout.addTab(tabLayout.newTab().setText("Transaction Details"));
    tabLayout.addTab(tabLayout.newTab().setText("Your Tab Title2"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    viewPager = (ViewPager) findViewById(R.id.simpleViewPager);
    //Creating our pager adapter
    pager adapter = new pager(getSupportFragmentManager(), tabLayout.getTabCount());

    //Adding adapter to pager
    viewPager.setAdapter(adapter);
   /// if (tabLayout.getSelectedTabPosition()==0){
        init = new Tab1();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.linearLayout, init);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();

Any help would be deeply appreciated

John
  • 3
  • 2

2 Answers2

0

You could try this one:

  1. Create a variable of the type ViewGroup locally to the function onCreate, then initialize it.

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.nameoflayout, container, false);
    
  2. Then, you could set you TextView using this:

    TextView txtView = (TextView)root.findViewByID(R.id.nameoftextviewid);
    
  3. Return variable root.

This is exactly what I'm doing in my projects.

Pang
  • 9,564
  • 146
  • 81
  • 122
0

Please Try this....

  ViewGroup root = (ViewGroup) inflater.inflate(R.layout.nameoflayout, container, false);

        piechart= (PieChart)view.findViewById(R.id.pie_chart);
        barChart = (BarChart)view.findViewById(R.id.barchart);

     return view;

refrence link..refer

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54