How to create context menu

SDK Version: 

There are two main methods that you must implement to get this thing work.
First of all, implement and override the onCreateContextMenu():

  1. @Override
  2.         public void onCreateContextMenu(ContextMenu menu, View v,
  3.                         ContextMenuInfo menuInfo) {
  4.                 super.onCreateContextMenu(menu, v, menuInfo);
  5.                 menu.setHeaderTitle("Choose an option");
  6.                 menu.add(0, v.getId(), 0, "Add to favorites");
  7.                 menu.add(0, v.getId(), 0, "See details");
  8.         }

How to update custom listview images simply

SDK Version: 
So in this tutorial I'm going to show you how to refresh imageviews' contents periodically (let say by Handlers if you download the picture from web).
I had painful 2 days figuring out what's a good solution here, I tried to give IDs to imageviews and that sort of sick things, but believe me, it wasn't worth it. The solution is so simply that I hardly can believe.
What we're lookign for here is instead of create new Adapters and HashMaps (which contains ListView data), we just update it's values, and Android will do the trick for us.
The most important thing is DO NOT AT ANY CIRCUMSTANCES CREATE A NEW ADAPTER (or a new data source that holds the Adapter's data).
There's an exception of course, you obviously have to create a new Adapter in OnCreate() { }.

Let me show you how it works:

How to avoid OutOfMemory Error / OOM (The Ugly Truth Revealed)

SDK Version: 

ERROR/dalvikvm-heap(4204): 691456-byte external allocation too large for this process.
01-25 22:13:18.694: ERROR/(4204): VM won't let us allocate 691456 bytes 01-25 22:13:18.694

If you have ever got the message above, you are at the right place.

First of all the reason:
Heap size != External Memory size

Dalvik's external memory is limited to ~ 4MBs for each process (That is the Ugly Truth). If it overflows, you get the BitmapFactory.DecodeFile Error.
That's why even if you have like 2MB-s heap memory free, VM won't let you allocate ~700KB.
Since you can't modify external memory's size, you have to reduce your memory usage. This is the only solution I have, but it really works at least.

The solution:

Let say you have a nice big Gallery with lots of large images. An ImageAdapter class will provide all of the images that you are going to use. Therefore you'll need a List of ImageViews.

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() :

How to add external 3D fonts to your Android applications

SDK Version: 
Step 1.
First, go to, and find an eye-candy font, that you like the most. Look for „free 3d fonts”. I'm going to use this one:
After you have downloaded it, unzip if it is zipped.

Step 2.
Go to your project's location, open the „assets” folder, and create a new folder called „fonts”.
Copy and Paste your „xy.ttf” font to this new directory.

Step 3.
If you are using Eclipse, don't forget to refresh your project's directory tree, make sure your SDK can see your font file.

  1. /* Setting up fonts */
  2. Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/xtrusion.ttf");
  3. Typeface fontFace2 = Typeface.createFromAsset(getAssets(), "fonts/other.ttf");
  4. TextView someText = (TextView)findViewById(;

Data Storage tutorial, basic samples are included

SDK Version: 

    Data Storage Methods

  • Preferences
  • Preferences is a lightweight mechanism to store and retrieve key-value pairs of primitive data types.
  • Files
  • You can store your data in files on your mobile phone, or in a removable storage medium.
  • Databases
  • Android Api supports SQLite databases. All databases, SQLite and others, are stored on the device in /data/data/package_name/databases.
  • Network
  • You can also use the Internet to store and receive data, whether it's an SQLite database, or just a simple textfile.

Syndicate content