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资源作为参数传入进去

发布了34 篇原创文章 · 获赞 5 · 访问量 7477

猜你喜欢

转载自blog.csdn.net/qq_39438055/article/details/104158060