Tag: android-fragments

ActionBar Title dynamically change with fragment

I have 1 Activity with 3 Fragments inside (Home-Login-RestorePass) Initially, HomeFragment shows and the other two are hidden. I want that the ActionBar Title change depending on which Fragment is showing. I’m trying in my Activity with: public void setActionBarTitle(String title){ getSupportActionBar().setTitle(title); } @Override public void onResume() { super.onResume(); // Set title setActionBarTitle(getString(R.string.app_name)); } and […]

How to load the same screen preference in the detail PreferenceFragment

I am trying to do something like the settings preferences in android for tablet. When I click the “More” the the “Wireless & Networks” preferences screen is displayed on the right fragment, than if I touch the “VPN” , in the same fragment the “VPN” preferences screen is opened. How can I do that ? […]

Loading Android Google Map fragment managed by ViewPager

I can load a google map into an Android fragment that’s within an activity. That has been working fine. But now I want to use ViewPager to navigate between views (class android.support.v4.app.Fragment). It doesn’t seem possible to load a com.google.android.gms.maps.MapFragment into such a fragment. For example, in: import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; […]

getSupportFragmentManager doesn't compile on DialogFragment

How can I show this : public class TagsDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); builder.setView(inflater.inflate(R.layout.tags_dialog, null)); builder.setMessage(“This is a message”).setTitle(“TAGS”); return builder.create(); } } From inside my Fragment inside a ViewPager : public class MyFragment extends Fragment { @Override public View onCreateView(LayoutInflater […]

How to implement multi-windowed layout (like the default browser) (Editor with several open files)

I am writing an editor (of sorts) which I want to be able to have multiple windows open at the same time, and I want to be able to navigate between windows as can be done in the default browser (Internet) application. See picture: http://i.imgur.com/LM6Nz.png for clarification. My question is how to implement these windows; […]

Pass data between fragments

I want to transfer the user ID from the main Activity to a fragment. So in the main activity, I do: Fragment fragment = new Fragment(); final Bundle bundle = new Bundle(); bundle.putString(“id_User”, id); Log.i(“BUNDLE”, bundle.toString()); fragment.setArguments(bundle); And in the log I can see BUNDLE : Bundle[{id_User=1}] In the fragment, I test it in onCreate […]

How to show soft keyboard perfectly in fragment in Android?

I have an EditText inside a Fragment inside a Activity. My Activity layout: <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@drawable/login_bg”> … <FrameLayout android:id=”@+id/fragment_container” android:layout_width=”match_parent” android:layout_height=”match_parent”/> … </RelativeLayout> My Activity config in AndroidManifest.xml: <activity android:name=”com.demo.LoginActivity” android:configChanges=”orientation|keyboardHidden” android:launchMode=”singleTop” android:screenOrientation=”portrait” android:theme=”@style/activityTheme” /> My code that use to start fragment in Activity: private void startFragment(BaseFragment fragment, String tag) […]

PopBackStack but keep the first fragment in android

I am working on fragment transaction, and the backstack is like this: fragA => fragB => fragC => fragD I would like to return to fragA after back fromn the fragD fragD => onBackPress => fragA So, I tried code like: getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); but it clear all the backstack , how can I keep the […]

Customize FragmentTabHost set TabWidget on bottom

currently I’m trying to implement the FragmentTabHost for my project. I’m still new on this fragments but I found it very great in terms of reusing the layouts, etc which is why I wanted to push myself further on to it. Now I read the tutorials on how to create a Tabs with fragment and […]

Android TabLayout does not display contents anymore as soon as fragment is switched

I am using a navigation drawer in my project, with 5 fragments in it. In one fragment I have the in the design support library introduced TabLayout, which includes 2 Fragments. All works fine, except when I leave the fragment which has the TabLayout and switch back to it, all the content is gone. In […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.