My Blog List

Android FirstAid Coding

A Small Help From a Small Heart
Powered by Blogger.

A software professional, who still likes to code, likes to blog and loves gadgets.

Monday, 29 April 2013

UIMenuController in iphone

NOTE:
UIMenuController will only work if it becomes the first responder

- (void)viewDidLoad
{
    [super viewDidLoad];  
    UIBarButtonItem *addJobButton = [[UIBarButtonItem alloc] initWithTitle:@"Add Contacts" style:UIBarButtonSystemItemAdd
                                                                    target:self action:@selector(setAddContactTapped:event:)];
    self.navigationItem.rightBarButtonItem = addJobButton;
    [addJobButton release];
}
-(void)setAddContactTapped:(id)sender event:(UIEvent*)event{
    [self becomeFirstResponder];
     /*get the view from the UIBarButtonItem*/
    UIView *buttonView=[[event.allTouches anyObject] view];
    CGRect buttonFrame=[buttonView convertRect:buttonView.frame toView:self.view];
   
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    UIMenuItem *personMenuItem = [[UIMenuItem alloc] initWithTitle:@"Person" action:@selector(newPerson:)];
    UIMenuItem *companyMenuItem = [[UIMenuItem alloc] initWithTitle:@"Company" action:@selector(newCompany:)];
   
   // NSAssert([self becomeFirstResponder], @"Sorry, UIMenuController will not work with %@ since it cannot become first responder", self);
    menuController.menuItems = [NSArray arrayWithObjects: personMenuItem, companyMenuItem, nil];  
    [menuController setTargetRect:buttonFrame inView:self.view];
    [menuController setMenuVisible:YES animated:YES];
    [personMenuItem release];
    [companyMenuItem release];      
}

- (void) newPerson: (UIMenuController*) sender
{
 //Add you logic
}
- (void) newCompany: (UIMenuController*) sender

    //Add your logic
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    BOOL can = [super canPerformAction:action withSender:sender];
    if (action == @selector(
newPerson:) || action == @selector(newCompany:))
    {
        can = YES;
    }
    if (action == @selector(copy:))
    {
        can = NO;
    }
   return can;
}
- (BOOL) canBecomeFirstResponder {
    return YES;
}


Showing Activity Indicator Within UIAlertview in Iphone

ViewController.h
================

@interface ViewController : UIViewController{
    UIAlertView *alertLoader;
}

@end

ViewController.m
================

- (void)viewDidLoad
{
    [super viewDidLoad];  
    [self methodtocallWebservices];
}
-(void)methodtocallWebservices{   
    alertLoader = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    alertLoader.tag=1;
    [alertLoader show];   
}
- (void)didPresentAlertView:(UIAlertView *)alertView
{  
    if (alertView.tag== 1) {
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];       
        indicator.center = CGPointMake(alertView.bounds.size.width/2, alertView.bounds.size.height/3 * 2);       
        [indicator startAnimating];
        [alertView addSubview:indicator];       
        NSString *hostStr = @"@"http://rajuandroid.blogspot.com/api/contact_name_json";       
        NSURL *url = [[NSURL alloc] initWithString:hostStr];
        NSLog(@"login url:  %@",url);       
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
        [url release];
    }   
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
  //  [self.receivedData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    [self stopLoading];
    //[self handleError:error];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    [self stopLoading];  
}
-(void)stopLoading
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [alertLoader dismissWithClickedButtonIndex:0 animated:YES];
        [alertLoader release];
    });
}



Friday, 26 April 2013

How to add button in navigation bar in iphone/ipad/IOS



Adding system bar button

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]                             initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                               target:self 
                                style:UIBarButtonItemStyleBordered
                               action:@selector(postNewCase:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];

-(IBAction)postNewCase:(id)sender {
}

Adding image bar button

UIImage *buttonImage = [UIImage imageNamed:@"home_icon.png"];
UIButton *forwardButton = [UIButton      buttonWithType:UIButtonTypeCustom];
[forwardButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
forwardButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[forwardButton addTarget:self action:@selector(postNewCase:)
           forControlEvents:UIControlEventTouchUpInside];
   
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:forwardButton];
   

Adding plain button
UIBarButtonItem *postButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Post"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(postNewCase:)];
self.navigationItem.rightBarButtonItem = postButton;
[postButton release];

Add background image to navigation bar

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"navigationBar.png"] forBarMetrics:UIBarMetricsDefault];

Add logo to navigation bar
 UIImage *image = [UIImage imageNamed: @"new_kj_logo-150.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
   
    self.navigationItem.titleView = imageView;

Hide Navigation default back button
 self.navigationItem.hidesBackButton = YES;




Wednesday, 3 April 2013

How to handle null vallue in json iphone

id displayNameTypeValue = [object objectForKey:@"address"];
NSString *displayNameType = @"";
if (displayNameTypeValue != [NSNull null])
   displayNameType = (NSString *)displayNameTypeValue;
 
 
 
 

Tuesday, 2 April 2013

Camera Sample Code in Iphone

AppDelegate.h
=========
//
//  AppDelegate.h
//  Genius
//
//  Created by Rajendra on 02/04/13.
//  Copyright (c) 2013 __Rajuandroid.blogspot.com__. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navController;
@property (strong, nonatomic) ViewController *viewController;

@end


AppDelegate.m
============
//
//  AppDelegate.m
//  Genius
//
//  Created by Rajendra on 02/04/13.
//  Copyright (c) 2013 __Rajuandroid.blogspot.com__. All rights reserved.
//

#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate
@synthesize navController;
@synthesize window = _window;
@synthesize viewController = _viewController;

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = self.navController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

 ViewController.h

=============
 
//
//  ViewController.h
//  Genius
//
//  Created by Rajendra on 02/04/13.
//  Copyright (c) 2013 __Rajuandroid.blogspot.com__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
    UIBarButtonItem *cameraButton;
}
@property (nonatomic, retain) UIImage* attachedImage;
@property (nonatomic, retain) UIBarButtonItem *cameraButton;
@end
 

ViewController.m
================

//
//  ViewController.m
//  Genius
//
//  Created by Rajendra on 02/04/13.
//  Copyright (c) 2013 __Rajuandroid.blogspot.com__. All rights reserved.
//
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize attachedImage,cameraButton;
- (void)viewDidLoad
{
    [super viewDidLoad];
   
    cameraButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"camera.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showActionSheet:)];
   
    self.navigationItem.rightBarButtonItem = cameraButton;
    [cameraButton release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(IBAction)showActionSheet:(id)sender {
    UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose Photo", nil];
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    [popupQuery showFromToolbar:(UIToolbar *)self.view];
    [popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
   
    if (buttonIndex == 0) {
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentModalViewController:imagePicker animated:YES];
           
        }else {
            UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"" message:@"Camera is not available"
                                                                  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alertsuccess show];
        }
    } else if (buttonIndex == 1) {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:imagePicker animated:YES];
       
    }
    else if (buttonIndex == 2) {
        //cancel clicked
    }
   
}


#pragma mark - pictures

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    self.attachedImage = nil;
    [self dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   
    [picker dismissModalViewControllerAnimated:YES];
   
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
   
    self.attachedImage = image;
   
    dispatch_async(dispatch_get_main_queue(), ^{
        CGFloat scale = [self.view.window.screen scale];
        CGSize size = CGSizeMake(30., 30.);
        UIGraphicsBeginImageContextWithOptions(size, YES, scale);
        CGContextSetInterpolationQuality(UIGraphicsGetCurrentContext(), kCGInterpolationHigh);
        [image drawInRect:CGRectMake(0., 0., size.width, size.height)];
        UIImage* thumb = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
       
        cameraButton.image = thumb;
       
    });
}



@end








Wednesday, 13 March 2013

Supporting Multiple Screens in android by using TableLayout

This is a example code for designing UI which supports a variety of devices that offer different screen sizes and densities. For example, the UI for tablets and the UI for handsets appears same due to the following code style which uses TableLayout of android.

1.MainActivity.java
=================
package com.rajuandroid.blogspot.com;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends  Activity {   
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
            setContentView(R.layout.main);           
    }
}

2.layout/main.xml
===================
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutMiddle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:fillViewport="true" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white" >

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp" >

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:minHeight="50dp"
                android:padding="5dip" >

                <TextView
                    android:layout_width="30dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/currentselection"
                    android:textColor="#000000"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/selectedTv"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="#F7FE2E"
                    android:gravity="center"
                    android:text="text1"
                    android:textColor="#000000" />

                <TextView
                    android:id="@+id/selectedTimeTv"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="2"
                    android:background="#F7FE2E"
                    android:gravity="center"
                    android:text="u can set dynamically"
                    android:textColor="#000000" />
            </TableRow>
        </TableLayout>

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="35dp"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/apple"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/apple"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/banana"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/banana"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/bread"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/bread"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/burger"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/burger"
                    android:textColor="#FFFFFF" />
            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/candy"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/candy"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/chips"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/chips"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/coffe"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/coffe"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/cookie"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/cookie"
                    android:textColor="#FFFFFF" />
            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/egg"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/egg"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/milk"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/milk"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/orange"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/orange"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/pasta"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/pasta"
                    android:textColor="#FFFFFF" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/salad"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/salad"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/soda"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/soda"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/soup"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/soup"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/tea"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/tea"
                    android:textColor="#FFFFFF" />
            </TableRow>
        </TableLayout>

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >

            <TableRow
                android:id="@+id/tableRow34"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/now"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/now"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/fiveMinAgo"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/fiveminago"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/fifteenMinAgo"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/fifteenminago"
                    android:textColor="#FFFFFF" />
            </TableRow>

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:id="@+id/thirtyMinAgo"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/thirtyminago"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/oneHourAgo"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/onehourago"
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/twoHourAgo"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/twohago"
                    android:textColor="#FFFFFF" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow35"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:minHeight="50dp"
                android:padding="2dip" >

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@null"
                    android:gravity="center"
                    android:text=""
                    android:textColor="#FFFFFF" />

                <Button
                    android:id="@+id/send"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@drawable/presetbtnbg"
                    android:gravity="center"
                    android:text="@string/send1"
                    android:textColor="#FFFFFF" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2dip"
                    android:layout_weight="1"
                    android:background="@null"
                    android:gravity="center"
                    android:text=""
                    android:textColor="#FFFFFF" />
            </TableRow>
        </TableLayout>
    </TableLayout>

</ScrollView>

3.values/strings.xml
====================
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">RajuAndroidBlog</string>  
    <string name="currentselection">Current selection</string>
    <string name="apple">Apple</string>
    <string name="banana">Banana</string>
    <string name="bread">Bread</string>
    <string name="burger">Burger</string>
    <string name="candy">Candy</string>
    <string name="chips">Chips</string>
    <string name="coffe">Coffe</string>
    <string name="cookie">Cookie</string>
    <string name="egg">Egg</string>
    <string name="milk">Milk</string>
    <string name="orange">Orange</string>
    <string name="pasta">Pasta</string>
    <string name="salad">Salad</string>
    <string name="soda">Soda</string>
    <string name="soup">Soup</string>
    <string name="tea">Tea</string>
    <string name="fifteenminago">15 min ago</string>
    <string name="fiveminago">5 min ago</string>
    <string name="now">Now</string>
    <string name="twohago">2h ago</string>
    <string name="onehourago">1 hour ago</string>
    <string name="thirtyminago">30 min ago</string>
    <string name="send1">Send</string>

</resources>

4.drawable/presetbtnbg.xml
=========================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
     android:drawable="@drawable/button_newbg_selected"/>  <!--pressed -->
<item android:drawable="@drawable/btnnewbg" /> <!-- Normal -->
</selector>

5.Notes 
=============
"@drawable/btnnewbg"  is a black small image and "@drawable/button_newbg_selected" is a white small image.

btnnewbg

button_newbg_selected




6.Screenshots
=================