iT邦幫忙

0

android 呼叫fragment的某段副函示

如題我該怎麼呼叫其他頁面的副函示
請問我要怎麼打?
在同一個BaseLazyFragment底下
被執行

public class Fragment1 extends BaseLazyFragment

底下的 這行

   public void onLazyLoad() {
        initData();
        isFirstLoad =true;
    }
看更多先前的討論...收起先前的討論...
https://stackoverflow.com/questions/27217362/calling-a-method-in-one-fragment-from-another
我參考他的答案
她顯示
Attempt to invoke virtual method 'void com.example.useweb0204.Fragment1.onLazyLoad()' on a null object reference
這個是空的==

他標示這行" f1.onLazyLoad();"
所以我覺得因該是我的f1是空的 我在想是不是我有使用viewpage的關係 頭痛==

FragmentManager fm = getFragmentManager();
Fragment1 f1 = (Fragment1) fm.findFragmentById(R.id.Re1_tab1);
f1.onLazyLoad();
看起來是這樣 不過下面這篇好像也有一樣的問題

https://stackoverflow.com/questions/44682624/android-studio-call-fragment-method-from-other-fragment-or-activity
感謝您 !! 成功了 你幫我解決我花了一整天 還搞不出來的東西

能請問一下 你是從哪裡看到這篇的 我看"已連結" 都沒看到這篇
能告訴我你的方式嗎?
你可以試著用英文關鍵字搜尋
你的問題我英文用 android call another fragment function
然後跳錯誤 我用 call another fragment method error
其實你截錯誤加你在做的動作基本上都能找到
除非是很少人在使用的程式語言
多搜尋幾次就會抓到訣竅了 加油
感謝指導
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答