SectionsPagerAdapter - 找不到片段id的视图

时间:2015-04-14 21:48:07

标签: java android android-fragments

我有一个带滑动菜单的应用程序,我可以选择不同的片段,显示不同类型的ListFragments。

ListFragments将由我的数据库服务器中的JSON填充。 如果单击其中一个列表项,则会显示一个新片段,其中包含有关所选列表项的更多详细信息。

public void updateList(final Activity a, final ListFragment L) {

    adapter = new SimpleAdapter(a, mCommentList,
            R.layout.single_comment, new String[] {TAG_PIC_ID,TAG_CATEGORY, TAG_ACTIVITY, TAG_DATUM, TAG_AKTUSR, TAG_MAXUSR, TAG_GENDER, /*TAG_POST_ID,*/ TAG_TITLE, TAG_MESSAGE,
                    TAG_USERNAME }, new int[] { R.id.imgrow, R.id.category, R.id.activity/*R.id.id*/ , R.id.datum, R.id.aktusr, R.id.maxusr, R.id.gender, /*R.id.category,*/ R.id.title, R.id.message,
                    R.id.username });

    L.setListAdapter(adapter);

    ListView lv = L.getListView();  

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            int intid = (int)id;


            Details nextFrag= new Details();
            L.getFragmentManager().beginTransaction()
                .replace(R.id.frame_container, nextFrag, "Test")
                .addToBackStack(null)
                .commit();

        }


    });
}

当我从&#34;单身&#34;将它解决没问题,并显示DetailPage。

问题是当我使用SectionsPagerAdapter从TabbedActivity调用该函数时。

TabbedActivity

package info.androidhive.slidingmenu;

public class TabbedActivity extends Fragment {


SectionsPagerAdapter mSectionsPagerAdapter;

public static final String TAG = TabbedActivity.class.getSimpleName();

ViewPager mViewPager;


public static TabbedActivity newInstance() {
    return new TabbedActivity();
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_item_one, container, false);
    mSectionsPagerAdapter = new SectionsPagerAdapter(
            getChildFragmentManager());

    mViewPager = (ViewPager) v.findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    return v;
}


public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {


        Fragment fragment = new newEntrys();

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

        default:
            break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        Locale l = Locale.getDefault();
        switch (position) {
        case 0:
            return "Aktuelle Einträge";
        case 1:
            return "Vergangene Einträge";
        }
        return null;
    }
}}

TabbedActivity包含2个片段newEntry和oldEntry几乎相等。

package info.androidhive.slidingmenu.fragments;



public class RegisterdEvents_new extends ListFragment{

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


    View rootView = inflater.inflate(R.layout.read, container, false);


    return rootView;
}

public void startTask(){

    Read SO = new Read();


    Load LEvt = SO.new Load(getActivity(), this, "NEW");
    LEvt.execute();





}

public void onResume() {
    startTask();
    super.onResume();
}

}

因此调用上面的函数updateList 加载LEvt = SO.new加载(getActivity(),this,&#34; NEW&#34;);

但问题是我总是得到错误

No view found for id 0x7f0a000f (package:id/frame_container) for fragment Details{e3992e2 #0 id=0x7f0a000f Test}

有人可以帮我解决这个问题吗?

0 个答案:

没有答案