Creating a nice looking List dialog with images and text

This tutorial, will demonstrate how you can create a great looking selectiondialog, containing both text and images. This list can then be used either directly in an Activity, Fragment, or as an Activity looking like a dialog. In this example, I will go with the latter, and create an activity that looks like a selection dialog window, that, in this case will be used to choose a country. Creating such a selection list is easy if it should contain text

» Read more

How to create simple view separators

This will show you three ways to create nice looking view separators, to use between a row of buttons for example. The examples shows a LinearLayout with three buttons, that should get separators in between them. The third example may be the easiest one to implement, while the other ones gives you better customizability. Method one – Manually adding a view separator to the LinearLayout We can create a simple View that represents the separator, and just add it in between

» Read more

Android string.xml resource formatting

If you are using the strings.xml file for your applications string resources (which you should!) then you might have wondered what to do if you need to combine a string and a value. Take this text for example: Hi, my name is Ruben and I am 26 years old String resource formatting This can easily be solved by using string formatting to insert the values; Ruben and 26. In you strings.xml file, create a new string resource like

» Read more

Got a problem with spaces in strings.xml getting stripped away?

If you have a string in your strings.xml file that you want to have a space character in front or after the string itself, you may notice that this space gets trimmed away automatically. To avoid the string getting trimmed away, you can use one of the following tricks: Trick one – Wrapping the string in quotes If you wrap the string in a pair of quotes, the space will not get stripped away. Also, the quotes themselves does not

» Read more

How to detect changes to your Android Preferences

This will demonstrate how to listen for changes to the user preferences in your app, so  that you can perform tasks depending on what the user selected/changed on the preferences screen. I have an app, with a listfragment displaying rows of text. There is also a preferences screen (SettingsActivity.java) where users can set the sorting order of the list. When users change the sort order, the list should be refreshed, to disaply the items in the new order.

» Read more

How to cut off too long lines of text in Lists with ellipsize

If you are using lists in your app, and some of the list items have too long text, making it wrap to several lines like item number three in the following image, then this trick will show you how to create better looking lists. Before, Text wrapping to two lines: Your custom list item xml layout file may look like this: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android"

» Read more

Eclipse ADT has been updated. Brings nice features!

I just noticed throught Eclipse that ADT had been updated. The new ADT version brings some nice touches to the layout editor. Now you can select items and drag and drop them onto the layout. It’s a nice touch that will certainly help new android developers a lot. To get the new features, in eclipse go to Help and then Check for updates. You can read more in the ADT changelog. They have also tweaked the XML formatting. Which

» Read more

How to align your TabHost at the bottom of the screen

This little tip will show you how to align your TabHost at the bottom of the screen in your Android app, like this: I assume you know how to use the TabHost the usual way (I might write a tutorial on that later). Say you are using your TabHost the following way: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_

» Read more

How to easily extract strings from your Android code into the strings.xml file

This handy little feature can save a lot of time and manual work when working with Android apps. If you during Android development in Eclipse use hardcoded strings in your java code, like in the example below: package test.layout; import android.app.Activity; import android.os.Bundle; import android.widget.Button; public class LayoutTest extends Activity { private Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button) findViewById(R.id.Button01); btn.

» Read more

How to create Gradient Lines with Drawables in Android

This article will show you how to create simple gradient line separators to spice up the layout a little bit. We are going to create gradients like these: About Drawables First off, we are going to create a drawable. A drawable resource is graphics that can be drawn on the screen, it can be a couple of different things, here are some examples; Bitmaps – png, jpg or gif images Nine-Patch image – A png that can be stretched, to create buttons

» Read more