0

I'm trying to create swipe view With two tab bar in android.Below are my coding snippet.

Tab.java

 public class Tab extends FragmentActivity {
        ViewPager Tab;
        TabPagerAdapter TabAdapter;
        ActionBar actionBar;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            TabAdapter = new TabPagerAdapter(getSupportFragmentManager());


            Tab = (ViewPager)findViewById(R.id.pager);

            Tab.setOnPageChangeListener(
                    new ViewPager.SimpleOnPageChangeListener() {
                        @Override
                        public void onPageSelected(int position) {

                            actionBar = getActionBar();
                            actionBar.setSelectedNavigationItem(position);                    }
                    });

            Tab.setAdapter(TabAdapter);

            actionBar = getActionBar();

            //Enable Tabs on Action Bar
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            ActionBar.TabListener tabListener = new ActionBar.TabListener(){

                @Override
                public void onTabReselected(android.app.ActionBar.Tab tab,
                                            FragmentTransaction ft) {
                    // TODO Auto-generated method stub
                  //  Toast.makeText(getApplicationContext(), "Tab selected", 200).show();

                }

                @Override
                public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {

                    Tab.setCurrentItem(tab.getPosition());
                }

                @Override
                public void onTabUnselected(android.app.ActionBar.Tab tab,
                                            FragmentTransaction ft) {
                    // TODO Auto-generated method stub

                }};
            //Add New Tabs
            actionBar.addTab(actionBar.newTab().setText("Information").setTabListener(tabListener));
            actionBar.addTab(actionBar.newTab().setText("Work Force").setTabListener(tabListener));
            actionBar.addTab(actionBar.newTab().setText("Work Details").setTabListener(tabListener));

        }




    }

Information.java

import android.app.DatePickerDialog;
        import android.app.Dialog;
        import android.app.FragmentTransaction;
        import android.os.Bundle;
        import android.support.v4.app.Fragment;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.ArrayAdapter;
        import android.widget.DatePicker;
        import android.widget.EditText;
        import android.widget.Spinner;
        import com.example.project.project.database.MyDatabaseHelper;
        import java.util.ArrayList;
        import java.util.Calendar;
        import java.util.List;

public class Information extends Fragment implements View.OnClickListener {
    private Spinner spinner, spinner2, spinner3;

    private MyDatabaseHelper dbHelper;
    private com.example.project.project.API.InfoAPI ts;
    private static EditText txtDate;
    private DateDialog dialog;
    private static String a;
    private static String b;
    private static String c;
    private static String date1;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View info = inflater.inflate(R.layout.information, container, false);
        dialog = new DateDialog();
        txtDate = (EditText) info.findViewById(R.id.editText5);
        txtDate.setOnClickListener(this);

        addItemsOnSpinner();
        addItemsOnSpinner2();
        addItemsOnSpinner3();
        return info;
    }


  public void onClick(View arg0) {
    FragmentTransaction ft =getActivity().getSupportFragmentManager().beginTransaction();
    dialog.show(ft, "DatePicker");

}


        public void addItemsOnSpinner() {
            spinner = (Spinner)getView().findViewById(R.id.spinner); 
            List<String> list = new ArrayList<String>();
            list.add("1");
            list.add("2");
            list.add("3");

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);


        }

WorkDetailsTable.java

  import android.app.Dialog;
    import android.app.TimePickerDialog;
    import android.content.pm.ActivityInfo;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.text.format.DateFormat;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.EditText;
    import android.widget.Spinner;
    import android.widget.TimePicker;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;

     public void onClick(View v) {
            int id = v.getId();
           if (id == R.id.editTextTI1) {
            tp.setFlag(TimePick.FLAG_START_DATE);
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            tp.show(ft, "TimePicker");
        }

And I get errors as below:

Error:(294, 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)

PLEASE help me..I've tired searching around..THANKS :)

Hoo
  • 1,806
  • 7
  • 33
  • 66

2 Answers2

0

The error "Reached end of file while parsing" is probably showing up because you forgot to close a curly brace : `}´

Did you really post the full code of your files? If so, this is definitely the issue you have.

I don't know what IDE you are using, but i would recommend for you to use AndroidStudio or Eclipse IDE. They will show you the compile time errors right away so you will be able to fix them easily.

As for ViewPager usage, Android Developers provides some excellent resources. I recommend that you read into it a little:

http://developer.android.com/training/animation/screen-slide.html

There is also a sample app for you to download

As for your Edit:

getSupportFragmentManager() is not available in a Fragment class. so you need to call it like this.

getActivity().getSupportFragmentManager()

Please read a little more into android Fragments and Activitys to avoid such trivial errors.

Falco Winkler
  • 1,082
  • 1
  • 18
  • 24
  • i strongly recommend using an ide and read some resources - programming will be way more fun for you. – Falco Winkler Oct 03 '15 at 16:32
  • ok, so now I have changed to getActivity().getSupportFragmentManager().beginTransaction()but still no luck.I still getting FragmentTransaction cannot be converted to FragmentManager. It totally frustrating! – Hoo Oct 03 '15 at 17:23
  • Going through your code there seems a lot to be wrong. Maybe Try the sample app posted above, and adapt your changes there. Stack overflow can help you with specific questions, but we won't do the programming for you. – Falco Winkler Oct 03 '15 at 17:27
0

First, your code looks rather incomplete so it is rather hard to tell the exact issue.

Now, for the issues that I am able to see.

Tab.java

  1. I don't see your imports so I can't tell if you are importing the correct classes or not. From what I can tell you are using the support library.
  2. You appear to be mixing support ActionBar with the native one. You should be using getSupportActionBar().
  3. You appear to be using android.app.ActionBar.Tab and android.support.v7.app.ActionBar.Tab interchangeably. They are not the same beast. You should use the support one.

WorkDetailsTable.java

You are missing a lot of code there. Is that the complete file?

Information.java and WorkDetailsTable.java

  1. You are using android.app.FragmentTransaction but getSupportFragmentManager.beginTransaction() returns android.support.v4.app.FragmentTransaction.
  2. Your dialogs appear to be implemented using android.app.DialogFragment. You implement them with android.supportv4.DialogFragment instead.

Error Logs

You are getting those errors because you are using incompatible types. android.app.FragmentTransaction and android.support.v4.app.FragmentTransaction are different types.

phxhawke
  • 2,581
  • 23
  • 17
  • Please see http://stackoverflow.com/questions/32932937/error-creating-tabs thanks – Hoo Oct 04 '15 at 11:33