我正在開發一個Android應用程序,我在片段中獲取了一些數據,並且我想在其他片段中使用它們。 所以我一直在尋找創建一個包,用一個簡單的getBasicInfos()方法返回我的包,然後將其發送到我的其他片段得到它的活動。 但問題是,我不能在我的活動使用此方法。Android從片段發送數據活動
fragment = new DashboardFragment();
fragment.getBasicInfos(); //Does not recognize the method
toolbar.setTitle(getResources().getString(R.string.dashboard));
break;
我想知道是否有更好的方法,或者更簡單。
提示:你必須使用回調方法。 – kishorepatel
是''片段是'Fragment'類對象或''DashboardFragment類,這是'Fragment'的子類? –
閱讀http://developer.android.com/training/basics/fragments/communicating.html – Raghunandan