Skip to main content

Posts

Showing posts from July, 2012

Localization

Android supports a wide range of languages. If you want to know all the supported languages you can visit here  . Using localization concept one can display a text in a any language corresponding to his Locale. Suppose a client(may be a person from France) is interested in getting his app design in English when he is in a country where the locale is English and  in his country he would be looking to see his app in French. In this situation we can use Localization. Consider the following screen shots : The first snapshot is HELLO WORLD in French. When ever we change the Locale to France we can see the HELLO WORLD in French language. For this to happen we must do the following : Create a folder under the res folder with name   values-fr . Here 'fr' refers to French language. Create a strings.xml file similar to the one in the values folder.  If we need to display a TextView in different languages in different Locales, set the text of the textview using

Alert Box (code)

Now lets discuss a small topic which may be used sometimes. An Alert Box...................... Sometimes we may come across few alert boxes saying Do you want to continue with a single button or two or three buttons. Alert box, as the name suggests it alerts and interrupts the user to perform short tasks that are related to the application. When alert box is displayed the current task loses focus and the dialog accepts the whole focus. This simply means that we can interact only with the alert box and not with the previous task. Now lets get into the details how to display an alert dialog box in android. An Alert box can be done either through java code or inflating an xml file While we are inflating an xml file we can have any views other than buttons in the alert box. (This is a custom alert box). 1.A simple way to create an alert dialog is to set the theme property for the activity which you want to display as a alert dialog.            android:theme="@an

Custom List View

Some Times we may come across few situations where we need to display an image and information about the image beside it. consider the following image as an example :  This task can be accomplished in many ways and am gonna discuss a way using Base Adapter. In general a list view will contain only a single textview in each row  which will be inflated (by default) for the number of items.  But if we need another view other than a textview or an additional view we need to use an alternative. This inflation is done by using an additional xml file which will be inflated onto the list view. consider an xml file with a list view as below : main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >       <TextView

Android List View sample

List View  :   As the name suggests it displays items in a list.  The user gets a list of items (a scrollable one when the number of items are not sufficient in the screen )  and when clicked on any item in the list view displays details about the clicked item. By default the list items are textViews. If you observe a list view can be seen in Contacts list , messages , songs list etc in a mobile . A listView can be implemented in Android in two ways. Using   ListActivity  . Using   ListView in XML file  . Using listActivity In this we   dont write anything in the xml file except the layout.  My sample xml file looks like this :     android:layout_width="fill_parent"  android:layout_height="fill_parent"   android:orientation="vertical">   Here i am just setting the layout as a linear layout and giving the properties. And the Activity File looks like this :   public class ListExampleActivity exte