Android之一些常用方法

1、 getActivity():獲得Fragment依附的Activity對象

    /**
     * Return the {@link FragmentActivity} this fragment is currently associated with.
     * May return {@code null} if the fragment is associated with a {@link Context}
     * instead.
     *
     * @see #requireActivity()
     */   
    @Nullable
    final public FragmentActivity getActivity() {
        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
    }

2、 getContext():View類中提供的方法,在繼承了View的類中纔可以調用,返回的是當前View運行在哪個Activity中。

3、setText():給TextView設置文字的時候,會調用該方法,通常會把String或者String資源作爲參數傳入進去

發佈了64 篇原創文章 · 獲贊 5 · 訪問量 9326
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章