fragment

Fragment setuserVisibleHint true but getActivity returns null

强颜欢笑 提交于 2020-01-13 09:58:33
问题 I've been doing some logic inside of a fragment's setUserVisibleHint() method. I was always checking if isVisibleToUser is true and then used getActivity to return the activity. This was working well (100% of the time) until I updated the support library to the latest( support:appcompat-v7:24.2.0 ). Now getActivity always returns null. Are there some changes to the support library that explain this behaviour? @Override public void setUserVisibleHint(boolean isVisibleToUser) { super

Activity/Window/View三者的差别

早过忘川 提交于 2020-01-13 09:14:04
Activity/Window/View三者的差别,fragment的特点 Activity像一个工匠(控制单元),Window像窗户(承载模型),View像窗花(显示视图) LayoutInflater像剪刀,Xml配置像窗花图纸。 在Activity中调用attach,创建了一个Window 创建的window是其子类PhoneWindow,在attach中创建PhoneWindow 在Activity中调用setContentView(R.layout.xxx) 其中实际上是调用的getWindow().setContentView() 调用PhoneWindow中的setContentView方法 创建ParentView: 作为ViewGroup的子类,实际是创建的DecorView(作为FramLayout的子类) 将指定的R.layout.xxx进行填充 通过布局填充器进行填充【其中的parent指的就是DecorView】 调用到ViewGroup 调用ViewGroup的removeAllView(),先将所有的view移除掉 添加新的view:addView() Fragment 特点 Fragment可以作为Activity界面的一部分组成出现; 可以在一个Activity中同时出现多个Fragment

Update fragment on dialog fragment option selection

痴心易碎 提交于 2020-01-12 18:48:34
问题 I have fragment that on a component click pop-ups DialogFragment. This dialog fragment holds list of options. When an option from list is selected I want to notify fragment so I can run fields update procedure. I did something like this @Override public void onClick(DialogInterface dialog, int item) { updateSharedPreference(item); Log.e("ProfilePersonaListDialog", "Click on dialog, inside onClick"); OnCloseListDialogListener act = (OnCloseListDialogListener) getActivity(); act

Update fragment on dialog fragment option selection

江枫思渺然 提交于 2020-01-12 18:48:32
问题 I have fragment that on a component click pop-ups DialogFragment. This dialog fragment holds list of options. When an option from list is selected I want to notify fragment so I can run fields update procedure. I did something like this @Override public void onClick(DialogInterface dialog, int item) { updateSharedPreference(item); Log.e("ProfilePersonaListDialog", "Click on dialog, inside onClick"); OnCloseListDialogListener act = (OnCloseListDialogListener) getActivity(); act

AndroidX底部导航栏

社会主义新天地 提交于 2020-01-12 11:53:16
implementation 'me.majiajie:pager-bottom-tab-strip:2.3.0X' 布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <androidx.viewpager.widget.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"></androidx.viewpager.widget

Android - fragmentTransaction.replace() not works on support library 25.1.0

两盒软妹~` 提交于 2020-01-12 08:05:47
问题 I replace a FrameLayout with a fragment using fragmentTransaction.replace() . Layout: <FrameLayout android:id="@+id/articlesAppender" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> Replacing in Activity's onCreate: FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); articlesFragment = (ArticlesFragment) fragmentManager.findFragmentByTag(ARTICLES_FRAGMENT_TAG); if

Android fragments vs compound controls

强颜欢笑 提交于 2020-01-11 17:41:55
问题 Why should Android 3.0 fragments be used instead of compound controls? One can create a View inheritor or compound control once and use it everywhere. I've read http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html but did not find the answer. 回答1: The difference is that fragments have a life cycle (onPause, onCreate, onStart...) of their own. By having a life cycle, fragments can respond independently to events, save their state through onSaveInstanceState, and be

Android fragments vs compound controls

半城伤御伤魂 提交于 2020-01-11 17:41:47
问题 Why should Android 3.0 fragments be used instead of compound controls? One can create a View inheritor or compound control once and use it everywhere. I've read http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html but did not find the answer. 回答1: The difference is that fragments have a life cycle (onPause, onCreate, onStart...) of their own. By having a life cycle, fragments can respond independently to events, save their state through onSaveInstanceState, and be

WebView into a Fragment (android.support.v4)

做~自己de王妃 提交于 2020-01-11 17:09:43
问题 I got a tab menu using a ViewPager . Each tab contains fragments from android.support.v4 package (compatibility with old SDKs). One of the fragment is a WebView (called FragmentWeb ) and I want it to stay into the pager layout. The problem is when my WebView is inflated, it runs in fullscreen mode. Is there a way to keep web browser under my tabs ? Thank you My Fragment Class : FragmentWeb.java public class FragmentWeb extends Fragment { public View onCreateView(LayoutInflater inflater,

Android fragments overlap

自闭症网瘾萝莉.ら 提交于 2020-01-11 13:03:44
问题 I have an activity with two fragments, one to display a list and one to show the details of the clicked item. When starting the app the detail part is something static, once I click an item it should get replaced. The problem is that the old fragment is not being replaced, so both views are on top of each other. My activity layout is: <?xml version="1.0" encoding="utf-8"?> <fragment android:id="@+id/listFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout