Search This Blog

Thursday, 29 November 2012

How to handle the navigation click in blackberry

Hello friends,
                Here it is , in my previous post i told you about doing something on touchevents on any i am giving you the code which will handle click events on anyfield whether touch screen or no touch device....

Suppose we have a bitmapfield which we want to use as a button...we have two png's "abc.png" and for rollover we have "abcR.png"

So here it goes....


First we initialize the bitmap field like this...

BitmapField _button;

in construstor:

 _button = new BitmapField(){
public int getPreferredWidth(){
return 22;
public int getPreferredHeight(){
return 21;
public boolean isFocusable(){
return true;
public void onUnfocus(){
protected void drawFocus(Graphics graphics, boolean on) {
      XYRect focusRect = new XYRect();
           if (on) {
            graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
            graphics.drawBitmap(focusRect.x, focusRect.y, focusRect.width, focusRect.height,Bitmap.getBitmapResource("abcR.png"), 0,0);
//           this.setBitmap(Bitmap.getBitmapResource("help_rollover.png"));
public void layout(int maxWidth,int maxHeight){
super.layout(getPreferredWidth(), getPreferredHeight());


Now we will override the navigation click function and identify the field and do some action there:

public boolean navigationClick(int status,int time){
Field _focus = this.getLeafFieldWithFocus();
if(_focus instanceof BitmapField){
BitmapField _bitmap = (BitmapField)_focus;

//Do something....
return true;
return false;

Thsi will make your bitmap clickable whether its a touch event on that bitmap field on its a trackpad click....but only when this bitmap is in focus.....

Ask for any queries....

Friday, 16 November 2012

How to change the selectedRow textColor in tableView for xcode

Hello friends,
                 Here it is a simple but sometimes useful for how to change the text color on row selection in TableView for xcode:


In function:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


Do this :
cell.textLabel.textColor = [UIColor white Color];
cell.textLabel.highlightedTextColor = [UIColor blackColor];

 cell.detailTextLabel.textColor = [UIColor grayColor];
cell.detailTextLabel.highlightedTextColor = [UIColor redColor];

here what will happen , on initial loading the color for textLabel and detail text Label will be white and gray respectively,on selecting the row the color will change to black for textLabel and red for detailTextLabel.

Ask for any queries....

Thursday, 8 November 2012

Get Battery Level and temperature in Blackberry.

        Below is the code,for getting batteryLevel and battery temperature in Blackberry:


int _batteryLevel = DeviceInfo.getBatteryLevel();
int _batteryTemp  = DeviceInfo.getBatteryTemperature();


Wednesday, 7 November 2012

How to hide Keyboard in Blackberry

 Here is the simple one liner without explanations:



Thursday, 1 November 2012

CustomChoiceField for blackberry

Hello ,
  Here is the Class for custom choice field in blackberry.Credits to perumal_n on blackberry forums:

import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.component.ObjectChoiceField;
import java.lang.String;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.Font;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;

//import org.utility.DSConstants;

public class CustomChoiceField extends ObjectChoiceField {

private int _bgWidth = 110;
private int _bgHeight = 30;
private boolean _hasFocus = false;
String[] m_Choices;
private int m_ChoiceFieldWidth;
private int m_TextMarginRight = 5;
private int m_TextMarginLeft = 5;
private Bitmap DopDownImgOn, DopDownImgOff;
private Font FONT_PLAIN;
private String visibleText;
private int m_MarginTop;

public CustomChoiceField(String label, String[] choices, int initialIndex) {
super(label, choices, initialIndex,CustomLongChoiceField.FIELD_RIGHT);
m_Choices = choices;

DopDownImgOff = Bitmap.getBitmapResource("dropdown_s.png");
DopDownImgOn = Bitmap.getBitmapResource("dropdown_off_s.png");
FONT_PLAIN = Font.getDefault().derive(Font.PLAIN, 5, Ui.UNITS_pt);

Font currFont = Font.getDefault().derive(Font.PLAIN, 3, Ui.UNITS_pt);
for (int i = 1; i < choices.length; i++) {
if (m_ChoiceFieldWidth < currFont.getAdvance(choices[i]))
m_ChoiceFieldWidth = currFont.getAdvance(choices[i]);
m_ChoiceFieldWidth += m_TextMarginLeft + m_TextMarginRight;

public int getPreferredHeight() {
return _bgHeight;

public int getPreferredWidth() {
return _bgWidth;


protected void layout(int width, int height) {
if (m_ChoiceFieldWidth == 0) {
m_ChoiceFieldWidth = width;
_bgHeight = height;
super.layout(width, height);
setExtent(_bgWidth, _bgHeight);

protected void onFocus(int direction) {
_hasFocus = true;
// super.onFocus(direction);

public void setBusiness(String[] choices) {
this.m_Choices = choices;

protected void onUnfocus() {

_hasFocus = false;
// super.onUnfocus();

protected void paint(Graphics g)

// DopDownImg = Bitmap.getBitmapResource("scroll.PNG");

if (DopDownImgOn instanceof Bitmap) {

m_MarginTop = (DopDownImgOn.getHeight() - FONT_PLAIN.getHeight()) / 4;
visibleText = (getSelectedIndex() == -1 || getSelectedIndex() >= m_Choices.length) ? ""
: m_Choices[getSelectedIndex()];

if (_hasFocus == false) {
g.drawBitmap(0, 0, DopDownImgOff.getWidth(), DopDownImgOff
.getHeight(), DopDownImgOff, 0, 0);
} else {
g.drawBitmap(0, 0, DopDownImgOn.getWidth(), DopDownImgOn
.getHeight(), DopDownImgOn, 0, 0);

g.drawText(visibleText, m_TextMarginRight, m_MarginTop,
DrawStyle.ELLIPSIS, DopDownImgOn.getWidth() - 30);

// g.pushContext(clip, xOffset, yOffset);

// g.popContext();


Use your own images ....and youmay find the problems in DSConstants.Just used to know the device model.....omit this if you want.