Tag: android-fragments

Fragments: Remove all fragments in a view

The scenario I am faced with, is in my application I have a single pane and dual pane style layout. Rather than individually handle every single navigation operation possible between the screens, for every different style of layout, I am using a function which sets up the layout correctly when given the desired screen. It […]

How to get Google Maps object inside a Fragment

I am using fragments in my application and I am new for this. There is a fragment in which I want to display Google Map and want to get its object, for this I have a fragment in my XML and I want to inflate it in the Fragment itself. When I am trying to […]

Custom background color for selected item with “activatedBackgroundIndicator” Navigation Drawer

This question has been asked a lot on SO, and I have referenced all the answers. I am still left with the default Holo blue background for selected items on my navigation drawer. I am new to Java and I am confused about the “context” part of .setAdapter(). My project is a single Activity with […]

Fragment implements OnClickListener

I’ve got an application that I’m modernizing. One step of this process is changing to a Fragment based layout (using the Fragments from the support library). I converted my Activities into Fragments, and got the layout working nicely (using a ViewPager, cool stuff!) I was having my Activities implement OnClickListener for all of my button-pressing […]

converting activity into fragment

This is a simple code to play a sound on click off a button, this code was initially written in Activity but now i want to change it to Fragments. errors 1) The method setContentView(int) is undefined for the type Rajathmusic. 2) The method create(Context, int) in the type MediaPlayer is not applicable for the […]

Google+ Login Not working properly on Android fragment

I am working with google+ login to my application and when i done it using a activity its work charm and after that i move my code into a fragment and after that when i try to login to google+ its not working i have to open the fragment activity 2 times to login to […]

ListFragment does not accept my layout

According to this link: ListFragment android developers I want to set my custom layout for list, but it makes exceptions. Here is the code: public class ListFragmentActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); if(fm.findFragmentById(android.R.id.content) == null) { myListFragments list = new myListFragments(); […]

How to find the “last page” in a view pager. Or the total 'number' of views. Android Development

Thank you for your help in advanced. And sorry if this is a very silly question, but I cannot find it elsewhere. What I want, is basically, to determine the total amount of pages I have in my ViewPager when it is all set up, like in my code. I have tried (on a later […]

Activity with fragments does not resize when the keyboard opens

In my main activity there is a RelativeLayout that has 2 childs: An ImageView which serves as the background A LinearLayout that has 2 fragment containers activity_main.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_gravity=”bottom” tools:context=”${packageName}.${activityClass}”> <ImageView android:layout_width=”match_parent” android:layout_height=”match_parent” android:adjustViewBounds=”true” android:baselineAlignBottom=”false” android:scaleType=”fitStart” android:src=”@drawable/bg_image” /> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” android:paddingTop=”?android:attr/actionBarSize” android:layout_alignParentBottom=”true”> <LinearLayout android:id=”@+id/ContainerA” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_gravity=”center” android:orientation=”vertical” /> […]

Get screen width and height in a Fragment

If I extend activity in my app i can get width and height: DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int wwidth = displaymetrics.widthPixels; or Display display = getWindowManager().getDefaultDisplay(); stageWidth = display.getWidth(); stageHeight = display.getHeigth(); But at present i extend fragement and I can’t use the above code to get the width.

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