How to display an AlertDialog in your Android application

SDK Version: 

Here is an example of an applacation, that illustrates how you can create a simple AlertDialog. The dialog can display maximum three buttons.

How to use canvas in your android apps - Part 2

SDK Version: 

In the second part of this tutorial series, I will show you what you can do with canvas and paint.

If you complete the first part, your onDraw method in Panel class is similar as this:

  1.         @Override
  2.         public void onDraw(Canvas canvas) {
  4.                 Paint paint = new Paint();
  7.                 Bitmap kangoo = BitmapFactory.decodeResource(getResources(),
  8.                                 R.drawable.kangoo);
  9.                 canvas.drawColor(Color.BLACK);
  10.                 canvas.drawBitmap(kangoo, 130, 10, null);
  12.         }

We will use the the Paint type object this time. You can use it to draw lines, circles and text on your canvas. For example this two lines will draw a red circle for you.

  1. paint.setColor(Color.RED);

How to use canvas in your android apps - Part 1

SDK Version: 
If you want to use a custom layout with a canvas in your application, this tutorial may be useful to you. We will draw a kangoo at the end of this tutorial.

There is a cool article on site Custom View - HorizontalSlider, what you can use to understand the following code:

  1. [...]
  2. <com.helloandroid.canvastutorial.Panel android:id="@+id/SurfaceView01" android:layout_width="wrap_content"
  4. android:layout_height="wrap_content" android:maxHeight="40dip">
  5. </com.helloandroid.canvastutorial.Panel>
  6. [...]

This is your main.xml.

Your main class extends Activity and similar as the following code snip:

  1. public class Canvastutorial extends Activity {
  2.     /** Called when the activity is first created. */
  3.     @Override

Mastering Android Widget Development - Part5 - Final

SDK Version: 

In this last part of the tutorial we will implement buttons to the appWidget, which will directly interact with the appWidget functionality.
We will have 2 buttons, a plus button to add one more day to the target date, and a minus button to decrease time left by one day.

First add the buttons to the countdownwidget.xml layout:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   xmlns:android=""
  4.   android:layout_width="wrap_content"
  5.   android:layout_height="wrap_content" android:orientation="vertical">
  7. <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Time left"></TextView>
  8. <LinearLayout android:id="@+id/LinearLayout01"; android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">

Hello Baby widget feature update - notification tutorial

SDK Version: 

We have updated our Hello Baby widget, with a notification feature. So I'm using this opportunity, to show you how to use notifications with widgets.

Hello readers, my name is Tamas, and I'm the newest member of the team :)
Today we decided to update our Hello Baby widget, with a notification feature. So I'm using this opportunity, to show you how to use notifications with widgets.
The plan was to alert the user with a status bar notification 1,2,3 and 7 days before the days-left counter reaches 0.

How to make Tabs UI with icons

SDK Version: 

So here's how it's going to be look like:

Your class has to extend TabActivity:

  1. public class YourClass extends TabActivity {
  2. ...
  3. ...
  4. }

After that, here's how to configure a Tab:
1. Create a LinearLayout in your main.xml, with the id: "TabOne"
2. Paste these lines after onCreate() :

Developing a clothing game for Android

SDK Version: 
What the hell am I doing? Developing a clothing game for Android...

Last time I was really bored, i tried to make a simple clothing game for android.

Here is the tutorial:

Mastering Android Widget Development - Part4

SDK Version: 

As described in the previous part, we will use a Service to update the appWidget.
So we will have the Service below, which gets the command (right now we have only the update command), ant the appwidgetId, reads the date from sharedPreferences and updates the widget.

  1. package com.helloandroid.countdownexample;
  3. import java.util.Date;
  5. import;
  6. import android.appwidget.AppWidgetManager;
  7. import android.content.Intent;
  8. import android.content.SharedPreferences;
  9. import android.os.IBinder;
  10. import android.widget.RemoteViews;
  12. public class CountdownService extends Service {
  13.         // command strings to send to service
  14.         public static final String UPDATE = "update";
  16.         @Override
  17.         public void onStart(Intent intent, int startId) {
  18.                 //a command, to define what to do, will be important only in the next tutorial part, now there is only update command
  19.                 String command = intent.getAction();
  20.                 int appWidgetId = intent.getExtras().getInt(

Mastering Android Widget Development - Part3

SDK Version: 

I just come to a new discovery regarding widgets. I was developing an appwidget, which - just like the widgets we are trying to make in this series of tutorials - and tried it out multiple phones. Unfortunatelly on one of our test phones it didn't function properly. For random intervals it stopped to refresh, and it din't responded to button presses on the widget, only after 1-2 minutes. After hard work I discivered the following:

Buttons on appwiget can have their onclick flunctionality thorough RemoteViews.setOnClickPendingIntent(). This method gets a PendingIntent ap parametes to bound to a button. PendingIntent's can have 3 types created with

getActivity(Context, int, Intent, int)

getBroadcast(Context, int, Intent, int)

and getService(Context, int, Intent, int).

How to use custom designed numbers in your android widget

SDK Version: 
If you don't want to download external fonts into your application, this article will be useful to you. You can draw your own numbers for example in gimp from 0 to 9. Copy thoose numbers in to your project folder's res/drawable subfolder. Each number is a new png (for example: one.png, two.png...). Then don't forget to refresh this directory in eclipse.

In my last project I wrote an easy method, what I used to draw single numbers on a widget.

Syndicate content