简体   繁体   English

片段变化后失去焦点(ANDROID TV)

[英]Focus lost after Fragment Change (ANDROID TV)

 public void changeFragment(String str) {


    SecFragment nextFrag = new SecFragment();
    Bundle args = new Bundle();
    args.putString("site", str);
    nextFrag.setArguments(args);
    getFragmentManager().beginTransaction()
            .replace(((ViewGroup) getView().getParent()).getId(), nextFrag)
            .commit();


}

This is my way to change a fragment in my Android TV app.这是我在 Android TV 应用程序中更改片段的方法。 But after changing I cant navigate in my 2nd Fragment.但是更改后我无法在我的第二个片段中导航。 The focus gets lost.焦点会丢失。

I am actually using a copy of the Mainfragment just with other information, here is the 2ndFragment´s onactivitycreated method我实际上只是在使用 Mainfragment 的副本以及其他信息,这是 2ndFragment 的 onactivitycreated 方法

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    Bundle bundle = getArguments();
    if (bundle != null) {
        site = bundle.getString("site");
    }

    super.onActivityCreated(savedInstanceState);
    page = 1;

    list = new ArrayList<Movie>();
    prepareBackgroundManager();

    setupUIElements();
    loadRows1();
    setupEventListeners();
    Bitmap mIcon = BitmapFactory.decodeResource(act.getResources(), R.drawable.splash);
    bm = BackgroundManager.getInstance(act);
    //bm.attach(act.getWindow());
    bm.setBitmap(mIcon);

    SetupVideos(site);

}

Both Fragments extend to the same BrowseFragment Class which is included in Android Studio两个片段都扩展到相同的 BrowseFragment Class,它包含在 Android Studio 中

You should use the addToBackStack() which would make it easier to navigate.您应该使用 addToBackStack() ,这将使导航更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM