Was PreferenceFragment intentionally excluded from the compatibility package?

Discovering that PreferenceActivity contains deprecated methods (although these are used in the accompanying sample code) The deprecated methods are deprecated as of Android 3.0. They are perfectly fine on all versions of Android, but the direction is to use PreferenceFragment on Android 3.0 and higher. Can anyone tell me whether this was intentional? My guess … Read more

Is there a way to hide the system bar in Android 3.0? It’s an internal device and I’m managing navigation

Since this is not possible to do using a public API, I have found a way to do it in a very “hack-ish” way that requires a rooted device. Update: as user864555 pointed below, this is another solution $ adb remount $ adb shell mv /system/app/SystemUI.odex /system/app/SystemUI.odexold $ adb shell mv /system/app/SystemUI.apk /system/app/SystemUI.apkold $ adb … Read more

How to add a Dropdown item on the action bar

First option: menu/options.xml: <item android:icon=”@drawable/ic_menu_sort” android:showAsAction=”ifRoom”> <menu> <item android:id=”@+id/menuSortNewest” android:title=”Sort by newest” /> <item android:id=”@+id/menuSortRating” android:title=”Sort by rating” /> </menu> </item> Second option: menu/options.xml: <menu xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@+id/menuSort” android:showAsAction=”ifRoom” android:actionLayout=”@layout/action_sort” /> </menu> layout/action_sort.xml: <Spinner xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/ic_menu_refresh” android:entries=”@array/order” /> Docs for menu resources – http://developer.android.com/guide/topics/resources/menu-resource.html

MapView in a Fragment (Honeycomb)

I’ve managed to resolve this by using TabHost in fragment. Here is the idea (briefly): MainFragmentActivity extends FragmentActivity (from support library) and has MapFragment. MyMapActivity extends MapActivity and contain MapView. LocalActivityManagerFragment hosts LocalActivityManager MapFragment extends LocalActivityManagerFragment. And LocalActivityManager contains MyMapActivity activity in it. Example implementation: https://github.com/inazaruk/map-fragment.

How to hide action bar before activity is created, and then show it again?

Setting android:windowActionBar=”false” truly disables the ActionBar but then, as you say, getActionBar(); returns null. This is solved by: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); getActionBar().hide(); setContentView(R.layout.splash); // be sure you call this AFTER requestFeature This creates the ActionBar and immediately hides it before it had the chance to be displayed. But now there is … Read more

How do I add a Fragment to an Activity with a programmatically created content view

It turns out there’s more than one problem with that code. A fragment cannot be declared that way, inside the same java file as the activity but not as a public inner class. The framework expects the fragment’s constructor (with no parameters) to be public and visible. Moving the fragment into the Activity as an … Read more

Why fragments, and when to use fragments instead of activities?

#1 & #2 what are the purposes of using a fragment & what are the advantages and disadvantages of using fragments compared to using activities/views/layouts? Fragments are Android’s solution to creating reusable user interfaces. You can achieve some of the same things using activities and layouts (for example by using includes). However; fragments are wired … Read more

Animate the transition between fragments

You need to use the new android.animation framework (object animators) with FragmentTransaction.setCustomAnimations as well as FragmentTransaction.setTransition. Here’s an example on using setCustomAnimations from ApiDemos’ FragmentHideShow.java: ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); and here’s the relevant animator XML from res/animator/fade_in.xml: <objectAnimator xmlns:android=”http://schemas.android.com/apk/res/android” android:interpolator=”@android:interpolator/accelerate_quad” android:valueFrom=”0″ android:valueTo=”1″ android:propertyName=”alpha” android:duration=”@android:integer/config_mediumAnimTime” /> Note that you can combine multiple animators using <set>, just as you … Read more