0

I'm trying to create navigation drawer in my app. In one of my navigation drawer item, View , I want it to has 2 tabs with swipe view feature. I can create them separately, but when I try to do in 1, I get error.

MainActivity // for navigation drawer item

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

private void selectItem(int position) {

        Fragment fragment = null;

        switch (position) {
            case 0:
                fragment=new Information();
                break;
            case 1:

                fragment=new Claims1();
                Bundle bundle=new Bundle();
                bundle.putLong("ab",WorkDetailsTable.ab);
                fragment.setArguments(bundle);
                break;

            case 2:
                fragment=new ViewView();
                break;

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); 

            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            Log.e("MainActivity", "Error in creating fragment");
        }
    }
}

Information

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

      public void onClick(View arg0) {
            FragmentTransaction ft = getFragmentManager().beginTransaction(); 
            dialog.show(ft, "DatePicker"); //cannot resolve method show

        }

      public static class DateDialog extends android.app.DialogFragment implements DatePickerDialog.OnDateSetListener {
            //  EditText txtdate;
            T t;


            public DateDialog() {

            }



            public Dialog onCreateDialog(Bundle savedInstanceState)
            {

                final Calendar c=Calendar.getInstance();
                int year=c.get(Calendar.YEAR);
                int month=c.get(Calendar.MONTH);
                int day=c.get(Calendar.DAY_OF_MONTH);
                return new DatePickerDialog(getActivity(),this,year,month,day);
            }

            public void onDateSet(DatePicker view,int year, int month, int day)
            {
                String date=day+"-"+(month+1)+"-"+year;
                txtDate.setText(date);
                date1= txtDate.getText().toString();
                return ;
                //t.add(date);


            }
        }

ViewView

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

public class ViewView extends Fragment implements ActionBar.TabListener { // must either be declared abstract or...

    private ViewPager viewPager;
    private TabsFragmentPagerAdapter mAdapter;
    private ActionBar actionBar;
    private String[] tabs = {"Information", "receipt"}; // This are the two tabs in view item

  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View View1 = inflater.inflate(R.layout.viewview1, container, false);
        listView = (ListView) View1.findViewById(R.id.listView1);
        viewPager = (ViewPager) View1.findViewById(R.id.pager);
        mAdapter = new TabsFragmentPagerAdapter(getActivity().getSupportFragmentManager()); 
        viewPager.setAdapter(mAdapter);
        actionBar = getActivity().getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0; i < 2; i++) {
            actionBar.addTab(actionBar.newTab().setText(tabs[i]).setTabListener(this));
        }
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg) {
                // TODO Auto-generated method stub
                actionBar.setSelectedNavigationItem(arg);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }
        });

        BuildList();
        return View1;
    }

TabsFragmentPagerAdapter

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsFragmentPagerAdapter extends FragmentPagerAdapter {

    public TabsFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int index) {
        // TODO Auto-generated method stub

        switch(index) {
            case 0:
                return new UpdatePage2();
            case 1:
                return new Receipt();

        }
        return null;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 2;
    }

}

Error

Error:(85, 15) error: no suitable method found for show(android.support.v4.app.FragmentTransaction,String) method DialogFragment.show(FragmentManager,String) is not applicable (argument mismatch; android.support.v4.app.FragmentTransaction cannot be converted to FragmentManager) method DialogFragment.show(android.app.FragmentTransaction,String) is not applicable (argument mismatch; android.support.v4.app.FragmentTransaction cannot be converted to android.app.FragmentTransaction)

Error:(28, 9) error: ViewView is not abstract and does not override abstract method onTabReselected(Tab,FragmentTransaction) in TabListener

Tony
  • 2,515
  • 14
  • 38
  • 71

1 Answers1

5

You are getting this error because your MainActivity and ViewView activities are using

import android.app.Fragment;
import android.app.FragmentManager;

where as your TabsFragmentPagerAdapter is using

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

Use any one of them in all of your activites.

Archit Goel
  • 694
  • 5
  • 19
  • Change "import android.app.FragmentManager;" to "import android.support.v4.app.FragmentManager;" in MainActivity and ViewView – Archit Goel Nov 21 '15 at 11:08
  • Change "import android.app.FragmentManager;" to "import android.support.v4.app.FragmentManager;" in "ViewView" Activity too! – Archit Goel Nov 21 '15 at 11:17
  • please see my post again – Tony Nov 21 '15 at 11:25
  • @MikeM. hi. I have changed to `android.support.v4.app`. How to solve the two errors ? – Tony Nov 21 '15 at 11:31
  • Your "Information" activity has import android.support.v4..app.FragmentTransaction; Change it to import android.support.v4.app.FragmentTransaction; – Archit Goel Nov 21 '15 at 11:38
  • You have 2 dots after v4 – Archit Goel Nov 21 '15 at 11:41
  • After change to `public static class DateDialog extends android.support.v4.app.DialogFragment implements DatePickerDialog.OnDateSetListener {`, I still left one problem, which is `ViewView is not abstract and does not override abstract method onTabReselected(Tab,FragmentTransaction) in TabListener` – Tony Nov 21 '15 at 12:08