Posts

Showing posts from February, 2013

Android Multi format TextView

Hey Androids !!! This is going to be my very first post on Android development. You may know that I've written many posts on Dot Net, Java & iPhone. From today onwards, I will add Android to that list :) So, if you're in a situation that you need to have a single label(TextView) with multiple formats, then this will be the post for you. It becomes very simple when you know a bit of html. Here is a list of tags supported by Android TextView before you get started. Have a look at this before you start. Suppose you have a TextView named multiFormatView TextView multiFormatView; The first step is to build your HTML string. String htmlString = "<b>This is bold</b>"+"And this is not."; Now there is only one line of code. Just set the text to the TextView using. multiFormatView .setText(Html.fromHtml(htmlString)); That's it. So, it will print  This is bold. And this is not. You can juggle around with each o

XCode importing a file to whole project

Hi, Sometimes you may encounter situations where you have a file which is used frequently throughout the XCode project. This may be a configurations file which is used in 80% of your code files. Importing this in each file is a certain possibility(and the very normal way with no issues), but if you are lazy and just want to add it in one place, this is the post for you. If you analyze the project, there is a file named <project-name>.pch. There is a block of code which has the following. #ifdef __OBJC__     #import < UIKit/UIKit.h>     #import < Foundation/Foundation.h> #endif NOTE: As you can see, UIKit is already added and so is the Foundation framework. That is why you can use classes such as "UIView" or "NSArray" without any additional imports in your code file. That's just an extra bit of info for the curious !!!. So, likewise, we can add our commonly used file into that block as well in the following manner. #i

iOS Convert Seconds into hours,minutes and seconds

Hi all, In building iPhone applications you may have come across situations that you count some time in seconds, but wish to let the user view it in a more readable format such as 1 hour 38 minutes and 44 seconds. Here is a piece of code that I wrote if you need to get this done in your code. - ( NSString *)timeFormatted:( int )totalSeconds {     int seconds = totalSeconds % 60 ;     int minutes = (totalSeconds / 60 ) % 60 ;     int hours = totalSeconds / 3600 ;         NSString *timeString =@"";     NSString *formatString=@"";     if(hours > 0){         formatString=hours==1?@"%d hour":@"%d hours";         timeString = [timeString stringByAppendingString:[NSString stringWithFormat:formatString,hours]];     }     if(minutes > 0 || hours > 0 ){         formatString=minutes==1?@" %d minute":@" %d minutes";         timeString = [timeString stringByAppendingString:[NSString st