fragment

Fragment onListItemClick

耗尽温柔 提交于 2021-02-10 03:21:26
问题 My onListItemClick is never call when i click on item, the class is extends fragment not listfragment, because i have other view items in this fragment which is not list, so how to implement onlistitemclick in class extends fragment? class public class MainFiles extends Fragment { ArrayList<String> items; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.files, container, false); Button button_up = (Button

How to handle rotate screen and save data in Fragment?

笑着哭i 提交于 2021-02-08 08:20:05
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

How to handle rotate screen and save data in Fragment?

拈花ヽ惹草 提交于 2021-02-08 08:17:24
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

How to change data of Main Activity from Fragment [closed]

瘦欲@ 提交于 2021-02-08 08:00:40
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Improve this question I Have fragment 1, fragment 2, fragment 3 which are in the Main Activity. there is a TextView in the main Activity, how can the fragments change the text in the text view? I already did the casting (Actvity).getActivity but i don't want my app to have error when changing

Previous fragment is restarting when we go back to previous fragment using backstack in android

瘦欲@ 提交于 2021-01-29 10:09:15
问题 lets say we have two fragment and we are in second fragment then if someone press back button then we successfully go back to the previous fragment (i.e. first fragment) using backstack but the problem is that the previous fragment is restarting everything. I want to display content of previous fragment without any restarting or initializing when we press back button.Thanks in advance. 回答1: Welcome to Android Fragment Life !! As suggested by @Uuu Uuu, you need to use add() method while adding

Kotlin in xml onClick not work

孤者浪人 提交于 2021-01-27 05:59:36
问题 I learning kotlin, and now for me not cearly some moment. I have xml <ImageView android:id="@+id/aries" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:tag="1" android:onClick="clickItemHoro" android:src="@drawable/aries" /> and fragment class ChooseYourHoroscope : Fragment(){ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment

Kotlin in xml onClick not work

元气小坏坏 提交于 2021-01-27 05:59:17
问题 I learning kotlin, and now for me not cearly some moment. I have xml <ImageView android:id="@+id/aries" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:tag="1" android:onClick="clickItemHoro" android:src="@drawable/aries" /> and fragment class ChooseYourHoroscope : Fragment(){ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment

Circular Reference with Nested Nav Graphs

前提是你 提交于 2021-01-27 05:40:56
问题 I have a complex navigation structure, I go from one nav graph then based on some logic, decide which nav graph to go to there. However both the nav graphs share 3 other nav graphs. See image below Currently I get a circular reference error if I try to include each nav graph in the A & B. I have also tried creating a global action, which leads to illegal argument exception since it doesn't exist on the nav graph. Please help!!! 来源: https://stackoverflow.com/questions/61083805/circular

How to use interface to communicate between fragment and activity?

痴心易碎 提交于 2021-01-05 07:32:42
问题 I simply want to call a Fragment method from my MainActivity. So I tried to use an Interface. public interface MyInterface { void testMethod(); } In my Fragment (TestFragment.java) I implement the interface and overrite the testMethod method. @Override public void testMethod() { Toast.makeText(getActivity(), "Test", Toast.LENGTH_LONG).show(); } but now I want to call this method from my MainActivity as soon as the onRewardedVideoCompleted get's called, but I'm not sure how to do it. I tried

How to know when fragment actually visible in viewpager

廉价感情. 提交于 2020-12-25 10:59:16
问题 I am using 4 fragments inside a ViewPager ,as ViewPager load the previous and next fragment in advance ,and no lifecycle method is called when navigating between fragments. So is there any way to detect when Fragment is actually visible. Thanks in Advance. 回答1: Of course. Assuming that viewPager is your instance of the ViewPager , use: viewPager.getCurrentItem() . Within your Fragment you can check if its instance is visible to the user like so: @Override public void setUserVisibleHint