fragment

Viewpager pass bundles between fragments

我们两清 提交于 2020-01-03 04:18:33
问题 I have a custom Viewpager in which it disables the touch events. So I have buttons 'Next' and 'Back' that control the viewpager. My question is how to pass data or bundles between the fragments in the viewpager. Normally it would work but sense the fragments are created even though they are not shown. That's because of the viewpager slide effect, it has to make the fragments ahead and before for the effect to work. So that means I can't use bundles since the fragment is already created. This

fragment +viewpager嵌套fragment空白

Deadly 提交于 2020-01-02 18:06:19
通过断点,发现新建 fragment 对象时,没有执行生命周期, 找到原因:猜想可能是由于之前实例的fragment缓存, 解决方案:清理掉fragmentmanager中的fragment缓存 注意点: 1、fragmentmanager在fragment中要用 getChildFragmentManager() 2、Transaction的commit方法有两个,要使用 commitNow ()才能立刻清掉缓存 List<Fragment> fragmentList = getChildFragmentManager().getFragments(); boolean cache = fragmentList != null && fragmentList.size() > 0; // 先清理缓存 if (cache){ FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); for (Fragment fragment:fragmentList){ fragmentTransaction.remove(fragment); } fragmentTransaction.commitNow(); } 启发来源于:https://www.jianshu.com/p

Android: get DatePickerDialog in a fragment

依然范特西╮ 提交于 2020-01-02 08:36:09
问题 Previously i was using showDialog() which now is deprecated. I am already in a Fragment which contains an EditText. How can i call this DatePickerDialog and set the EditText's Text to the selected date? Using DialogFragment seems a bit complicated. Thank You 回答1: Its easy: DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay =

Android and Google map inside fragment with other controls and viewpager

烈酒焚心 提交于 2020-01-02 08:11:22
问题 I'm new in android programming; I have that small app with 3 pages (fragments), swiping between them using pageradapter and viewpager; one of these pages contains checkbox [and other controls] and a map; my problem is that the program is crashing on start. Fragment_compass.java package com.ibdiab.emadaldien; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android

Android fragments lifecycle onStop, onDestroyView, onDestroy and onDetach

允我心安 提交于 2020-01-02 06:39:10
问题 Android documentation talks about onStop an onDestroy couldn't be called in some circustances, but i didn't find nothing about the same with fragments. Is onPause, onStop, onDestroyView, on Destroy and onDetach always called? Only on Pause? 回答1: It's the same for Fragments , so only onPause is always called. Most of these callbacks are called at the same time (before or after to be exact) corresponding callbacks from Activity are called, when the fragment is added via xml layout. Note that on

Pass fragments between activities

[亡魂溺海] 提交于 2020-01-02 03:14:30
问题 I want to make an application that can support portrait and landscape. The layout has two panes, on the left is the options and the right shows the result. When an option is selected the right pane shows it. But for portrait there is not enough room, so a separate activity is needed. Each option produces a different type of fragment, so I don't want to make an activity for each option when all that changes between activities is what fragment is being added there. I want to pass a fragment

Pass fragments between activities

可紊 提交于 2020-01-02 03:14:05
问题 I want to make an application that can support portrait and landscape. The layout has two panes, on the left is the options and the right shows the result. When an option is selected the right pane shows it. But for portrait there is not enough room, so a separate activity is needed. Each option produces a different type of fragment, so I don't want to make an activity for each option when all that changes between activities is what fragment is being added there. I want to pass a fragment

How to remove the focus of the back stack fragment?

社会主义新天地 提交于 2020-01-02 03:13:28
问题 I am using fragments in my application.I have a fragment that contains EditText and some Dialogfragment . When i click one particular widget it will move to next fragment. I need the first fragment in the backstack,so i added addToBackStack method also. The second fragment doesn't contain any EditText . Now the problem is, when we touch or press the second fragment, EditText in the first fragment get the focus and the dialogs are coming. I got the following code getView()

Creating Tabs inside Fragment

浪尽此生 提交于 2020-01-01 19:55:49
问题 I'm getting a fragment from mother activity. Now i want to create tabs in this fragment. But tabHost.setup() method showing error. I don't get it so need a clue about error. // FragmentOne.java package com.example.sharelocationui; import android.app.Fragment; import android.os.Bundle; import android.support.v4.app.FragmentTabHost; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView.FindListener; import android.widget

Unable to switch from Fragment to Activity / Activity to Fragment in Android Programming

感情迁移 提交于 2020-01-01 19:06:23
问题 Currently, I am mainly using Fragments to connect to Facebook. However, for the other codes, I am using normal activites (no Fragments). My issue now is that I wish to have a button to link from my "Home Page" to the Fragment, and from the Fragment back to my "Home Page" I am unable to do so. I tried to use the same code to switch between activities for this but it does not work. Is there a way to Link Normal Activities to Fragments and Vice Versa ? Or can they only link to each other ? This