Archiv for March, 2011


published: March 28th, 2011

Using an Android View to display a line

Here’s a cool trick I’ve used a couple times to display a horizontal line on the screen between widgets. It uses an Android View with a background color.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        style="@style/WordsOfWisdomText"
	android:text="Turn off your lights to safe energy"/>
    <View
	android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#FF909090" />
    <TextView
	style="@style/WordsOfWisdomText"
	android:text="World peace is a reality"/>
    <View
	android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:background="#FF909090" />
    <TextView
	style="@style/WordsOfWisdomText"
	android:text="Eat your vegetables"/>

</LinearLayout>

(more…)

published: March 23rd, 2011

Inflating a view for a AlertDialog

I’m in the process of updating Jumpy not only to give it some polish, but also learn more of the ins and outs of the Android Market marketing capabilities…hopefully I’ll also figure out how to insert advertising and possibly make a little extra cash.

Anywho, as I’ve been updating some of the code, I came across my custom AboutDialog and decided it needed to go into an AlertDialog instead.  By using the code below, I was able to use the same layout resource of the AboutDialog (removing a couple widgets) and fully utilizing the AlertDialog by instantiating a View via the LayoutInflater and setting it into the AlertDialog.

    private void openAboutDialog()
    {
    	AlertDialog.Builder dialog = new AlertDialog.Builder( this );
    	dialog.setView( getLayoutInflater().inflate( R.layout.about_layout, null ) );
    	dialog.setTitle( getString( R.string.about_jumpy_title ) );
    	dialog.setPositiveButton( getString( R.string.done ), null );
    	dialog.show();
    }

It’s really nice that with the getLayoutInflater().inflate call you only have to supply the resource since the root ViewGroup is optional.  Now I’m able to get rid of the AboutDialog class and remove 50 some odd lines of code from the applications.