我在片段中实现寻呼机,但出现此错误
对于
HowToUse_phone类型,方法 getSupportFragmentManager() 未定义
上
mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager());
这里的代码,
package com.chocte.ks_documents;
import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
public class HowToUse_phone extends SherlockFragment{
private LinearLayout lLayoutFrgHow;
ViewPager mViewPager;
SectionsPagerAdapter mSectionsPagerAdapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//return inflater.inflate(R.layout.activity_how_phone, container, false);
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
//mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager = (ViewPager) getView().findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
//get the layou8t
lLayoutFrgHow=(LinearLayout) inflater.inflate(R.layout.activity_how_phone, container, false);
return lLayoutFrgHow;
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
//return getString(R.string.title_section1).toUpperCase(l);
return "a";
case 1:
//return getString(R.string.title_section2).toUpperCase(l);
return "b";
case 2:
//return getString(R.string.title_section3).toUpperCase(l);
return "c";
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
return rootView;
}
}
}
我在导入片段时看到了一些问题,但正如您在我的代码中看到的那样,我是 android.support.v4.app ...
还有什么问题?
谢谢!