无法转换为片段错误

时间:2015-05-28 21:36:28

标签: android-fragments android-activity incompatibletypeerror

我已经创建了一个滑动标签布局,并且在其中一个标签中我想在地图上工作...我是Android新手,我不知道我是否做得对... < / p>

我试图制作一个活动并试图将活动附加到片段......

我的片段Tab2.java中的代码是

&#13;
&#13;
txt <- "hello
world
123

bye
world
456

byee
world
456678"
temp <- data.frame( scan(text=txt, 
                    what= list( word="", dest="", num=numeric(), "NULL"), 
                    multi.line=TRUE))
 write.table(temp, sep=",", file="", quote=FALSE,col.names=FALSE)
#-------------
1,hello,world,123,
2,bye,world,456,
3,byee,world,456678,
&#13;
&#13;
&#13;

我的ViewPagerAdapter的代码是:

&#13;
&#13;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;


/**
 * Created by Rafaqat Rasool on 5/26/2015.
 */
public class Tab2 extends Fragment {
  GoogleMap googleMap;

  @
  Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.tab_2, container, false);


    return v;
  }

  @
  Override
  public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);


    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getBaseContext());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

      int requestCode = 10;
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), requestCode);
      dialog.show();

    } else { // Google Play Services are available

      // Getting reference to the SupportMapFragment of activity_main.xml
      SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);

      // Getting GoogleMap object from the fragment
      googleMap = fm.getMap();

      // Enabling MyLocation Layer of Google Map
      googleMap.setMyLocationEnabled(true);


    }

  }

}
&#13;
&#13;
&#13;

和MapT2.java的代码是

&#13;
&#13;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

/**
 * Created by Rafaqat Rasool on 5/26/2015.
 */
public class ViewPagerAdapter extends FragmentStatePagerAdapter {

    CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
    int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created


    // Build a Constructor and assign the passed Values to appropriate values in the class
    public ViewPagerAdapter(FragmentManager fm, CharSequence mTitles[], int mNumbOfTabsumb) {
        super(fm);

        this.Titles = mTitles;
        this.NumbOfTabs = mNumbOfTabsumb;

    }

    //This method return the fragment for the every position in the View Pager
    @Override
    public Fragment getItem(int position) {

        if (position == 0) // if the position is 0 we are returning the First tab
        {
            Tab1 tab1 = new Tab1();
            return tab1;
        }else if(position == 1){
            Tab2 tab2 = new Tab2();
            return tab2;

        }
        else             // As we are having 3 tabs if the position is now 1 it must be 2 so we are returning third tab
        {
            Tab3 tab3 = new Tab3();
            return tab3;
        }


    }

    // This method return the titles for the Tabs in the Tab Strip

    @Override
    public CharSequence getPageTitle(int position) {
        return Titles[position];
    }

    // This method return the Number of tabs for the tabs Strip

    @Override
    public int getCount() {
        return NumbOfTabs;
    }
}
&#13;
&#13;
&#13;

在上面的类中我得到错误(无法解析方法&#39; add(int,com.example.rafaqatrasool.optiroute.Tab2))因为无法将Tab2转换为Fragment ....我已经检查了我的导入他们都支持.v4.app.Fragment ...我不知道发生了什么......请帮帮我

0 个答案:

没有答案
相关问题