Saturday, September 15, 2012

Android UI Basic Views,Progressbar and Picker views Tutorial

Android UI Basic Views,Progressbar and Picker views Tutorial - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul Android UI Basic Views,Progressbar and Picker views Tutorial, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan Artikel Android UI Basic Views, Artikel Progressbar and Picker views Tutorial, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : Android UI Basic Views,Progressbar and Picker views Tutorial
link : Android UI Basic Views,Progressbar and Picker views Tutorial

Baca juga


Android UI Basic Views,Progressbar and Picker views Tutorial

UI Interface Components

         All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface. For Learning UI for Android you need to have the understanding of the following user interface components
 Activity
An Activity represents the visual representation of an Android application. Activities use Views and Fragments to create the user interface and to interact with the user.
An Android application can have several Activities.
Fragments (Android 3 and above or use support library for lesser versions)
Fragments are components which run in the context of an Activity. Fragment components encapsulate application code so that it is easier to reuse it and to support different sized devices.
Fragments are optional, you can use Views and ViewGroupsdirectly in an Activity but in professional applications you always use them to allow the reuse of your user interface components on different sized devices.
Views and ViewGroups
Views are user interface widgets, e.g. buttons or text fields. The base class for all Views is the android.view.Viewclass. Views have attributes which can be used to configure their appearance and behavior.
A ViewGroup is responsible for arranging other Views. ViewGroupsis also called layout managers. The base class for these layout managers is the android.view.ViewGroupclass which extends the Viewclass.
ViewGroups can be nestled to create complex layouts. You should not nestle ViewGroups too deeply as this has a negative impact on the performance.
                                Figure 1 Shows the views and view group tree hierarchy
             To declare your layout, you can instantiate View objects in code and start building a tree, but the easiest and most effective way to define your layout is with an XML file. XML offers a human-readable structure for the layout, similar to HTML.
The name of an XML element for a view is respective to the Android class it represents. So a <TextView> element creates a TextView widget in your UI, and a <LinearLayout> element creates a LinearLayout view group.
For example, a simple vertical layout with a text view and a button looks like this:
<?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:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="I am a Button" />

</LinearLayout>

Activities, Fragments and Views
Activities are defined with different layouts. These layouts can be picked based on several different factoring including the size of the actual device.
Input controls are interactive components in your app's user interface. Android provides a wide variety of controls you can use in your UI.Adding an input  to your UIcontrols are done by simply adding an XML element to your XML layout
 .
We can categorized the views in this series into the following group:
  Basic Views -  buttons, text fields, seek bars, checkboxes, zoom buttons, toggle buttons, and many more 
Figure 2 Shows the basic views of android
  Picker Views - views that allows users to select from, such as the TimePicker and DatePicker views.
  Adapter views-If you want the user to choose something out of a collection of somethings, you
could use a bunch of RadioButton widgets. However, Android has a series of more
flexible widgets than that, ones that this book will refer to as “selection widgets”.
These include:ListView, which is your typical “list box”, Spinner, which (more or less) is a drop-down list.
  GridView, offering a two-dimensional roster of choices, ExpandableListView, a limited “tree” widget, supporting two levels in the hierarchy 
Display Views - views that display images, such as the Gallery and ImageSwitcher views
  Menus and Action Bar- views that displays additional and context sensitive menu items.
The options menu is the primary collection of menu items for an activity. It's where you should place actions that have a global impact on the app, such as "Search," "Compose email," and "Settings."
If you're developing for Android 2.3 or lower, users can reveal the options menu panel by pressing the Menu button.On Android 3.0 and higher, items from the options menu are presented by the action bar as a combination of on-screen action items and overflow options.
Additional Views - interesting views such as the AnalogClock and DigitalClock views
Dialogs,Notifications,Toast -display to the user outside of your application's normal UI.

In this section, you will examine the basic views in Android that allow you to display text information as well as perform some basic selection. In particular, you will learn about the following views:
1.The TextView view is used to display text to the user. This is the most basic view that you will definitely come across when you develop Android applications. 
2. Button : Represents a push-button widget
3. ImageButton :Similar to the Button view, except that it also displays an image
4. EditText : A subclass of the TextView view that allows users to edit its text content.
5. CheckBox : A special type of button that has two states: checked or unchecked
6. RadioGroup and RadioButton : The RadioButton has two states: either checked or unchecked.. A RadioGroup is used to group together one or more RadioButton views,thereby allowing only one RadioButton to be checked within the RadioGroup.
7. ToggleButton : Displays checked/unchecked states using a light indicator.
8.SeekBar:A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys.
9.RatingBar:A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar
The Demonstrative project portrays Basic views in android  
1.Create  Android project with details as listed in table below.
Property name
Property value
Project name
SRM_BasicViewsTutorial
Package name
in.ac.srmuniv.basicviews
Activity name
MainActivity
Layout xml name
activity_main

2.Copy the code to the res/layout folder and name it as activity_main.xml. 
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btnOpen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open" />

    <ImageButton
        android:id="@+id/srmbutton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/srm" />

    <ToggleButton
        android:id="@+id/toggle1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/txtName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapSentences|textAutoCorrect" />

    <CheckBox
        android:id="@+id/chkAutosave"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Autosave" />

    <RadioGroup
        android:id="@+id/rdbGp1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/rdb1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Option 1" />

        <RadioButton
            android:id="@+id/rdb2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Option 2" />
    </RadioGroup>

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progress="100" />

    <RatingBar
        android:id="@+id/setRating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1.0" />

</LinearLayout>
Note that you use the id attribute to identify each view. The id of a view must start with the "@+id/" specifier followed by the name of the view.
3.Copy the code in MainActivity.java. Activity.
packagein.ac.srmuniv.basicviewstutorial;

importandroid.app.Activity;
import android.os.Bundle;

importandroid.text.Editable;
import android.view.View;
importandroid.widget.Button;
importandroid.widget.CheckBox;
importandroid.widget.EditText;
importandroid.widget.RatingBar.OnRatingBarChangeListener;
importandroid.widget.SeekBar.OnSeekBarChangeListener;
importandroid.widget.RadioGroup;
importandroid.widget.RadioGroup.OnCheckedChangeListener;
importandroid.widget.SeekBar;
importandroid.text.TextWatcher;
importandroid.widget.RatingBar;
import android.widget.Toast;
importandroid.widget.ToggleButton;

public class MainActivity extends Activity {

     @Override
     public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);

           // ---Button view---
           Button btnOpen = (Button) findViewById(R.id.btnOpen);
           btnOpen.setOnClickListener(newView.OnClickListener() {
                public void onClick(View v) {
                     Toast.makeText(getBaseContext(),
                                "You have clicked the Open button", Toast.LENGTH_SHORT)
                                .show();
                }
           });
           // ---ToggleButton---
           ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggle1);
           toggleButton.setOnClickListener(newView.OnClickListener() {
                public void onClick(View v) {
                     if (((ToggleButton) v).isChecked())
                           DisplayToast("Toggle button is On");
                     else
                           DisplayToast("Toggle button is Off");
                }
           });
           // ---EditText view---
           EditText text = (EditText) findViewById(R.id.txtName);
           text.addTextChangedListener(new TextWatcher() {

                @Override
                public voidafterTextChanged(Editable s) {
                     // TODO Auto-generated method stub

                }

                @Override
                public voidbeforeTextChanged(CharSequence s, int start, int count,
                           int after) {
                     // TODO Auto-generated method stub

                }

                @Override
                public voidonTextChanged(CharSequence s, int start, int before,
                           int count) {

                     DisplayToast("EditText text changed");
                }
           });

           // ---CheckBox---
           CheckBox checkBox = (CheckBox) findViewById(R.id.chkAutosave);
           checkBox.setOnClickListener(newView.OnClickListener() {
                public void onClick(View v) {
                     if (((CheckBox) v).isChecked())
                           DisplayToast("CheckBox is checked");
                     else
                           DisplayToast("CheckBox is unchecked");
                }
           });

           // ---RadioButton---
           RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rdbGp1);
           radioGroup.setOnCheckedChangeListener(newOnCheckedChangeListener() {
                public voidonCheckedChanged(RadioGroup group, int checkedId) {
                     // ---displays the ID of the RadioButton that is checked---
                     DisplayToast(Integer.toString(checkedId));
                }
           });

           SeekBar sbar = (SeekBar) findViewById(R.id.seekBar1);
           sbar.setOnSeekBarChangeListener(newOnSeekBarChangeListener() {

                @Override
                public voidonStopTrackingTouch(SeekBar seekBar) {
                     // TODO Auto-generated method stub

                }

                @Override
                public voidonStartTrackingTouch(SeekBar seekBar) {
                     // TODO Auto-generated method stub

                }

                @Override
                public voidonProgressChanged(SeekBar seekBar, int progress,
                           boolean fromUser) {
                     DisplayToast("Progress bar value " + Integer.toString(progress));

                }
           });
           final RatingBar setRatingBar = (RatingBar) findViewById(R.id.setRating);
           setRatingBar
                     .setOnRatingBarChangeListener(newOnRatingBarChangeListener() {

                           @Override
                           public voidonRatingChanged(RatingBar ratingBar,
                                     float rating, boolean fromUser) {
                                DisplayToast("New Rating: " + rating);

                           }
                     });
     }

     private void DisplayToast(String msg) {
           Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
     }


}

4.No need to modify Androidmanifest.xml
5.Run the application in the emulator. 

Figure 1 Shows how the various views  ready to handle the various common events associated with the various views.
Figure 2 Shows Button clicked                           Figure 3 Shows Toggle Button clicked On





Figure 4 Shows Content Typed in EditText calls the onTextChanged() method of TextWatcher Listenet
Figure 5 Shows Check Box checked  calling onClickListener,s OnClick method  

Figure 6 Shows option RadioButton clicked in RadioGroup radio button ID is displayed in Toast.
Figure 7 Shows Progress Bar changed with progess value fetched is displayed in Toast

Figure 8 Shows Rating bar seleted and Toast displays the Rating Value
CODE EXPLANATION
          The layout contains basic views with id assigned for all the views.In the MainActivity all the Views are instantiated by the factory design pattern method  findViewById() by passing the view ID as parameter.All the Views are set with appropriate listeners.On user interaction respective callback functions of the listeners are called in which business logic code are written.Here we have called Toast message to display the user interaction on each Views.The listeners implemented for respective Views are listed below.
Button-OnClickListener.
ToggleButton-OnClickListener
EditText-TextWatcher
CheckBox-OnClickListener
RadioGroup-OnCheckedChangeListener
SeekBar-OnSeekBarChangeListener
RatingBar-OnRatingBarChangeListener

For the EditText view, you can also set it to accept passwords by replacing each character with a ".". This is done using the password attribute. 
<EditText
    android:id="@+id/txtName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:password="true" />
Similarly EditText property android:inputType can set the input type entry to "phone" to accept only numbers etc.
ProgressBar View
The ProgressBar view provides visual feedback of some background tasks. For example, you might be downloading some data from the web and need to update the user of the status of the download. In this case, the ProgressBar view is a good choice for this task.
        The default mode of the ProgressBar view is indeterminate - that is, it shows a cyclic animation. This mode is useful for tasks that do not have a clear indication of when they will be completed. For example, you are sending some data to a web service and waiting for the server to respond.If you are downloading a file of known size then it can show a bar representing the completing of the task. Normally the ProgresBar do not display the amount of completion in numbers.If we want, we can display it in the TextView.
The Demonstrative project portrays the usage of Progress Bar with various features.
1.Create  Android project with details as listed in the table below.
Property name
Property value
Project name
SRM_ProgressBarTutorial
Package name
in.ac.srmuniv.progressbartutorial
Activity name
MainActivity
Layout xml name
activity_main
2.Copy the code to the res/layout folder and name it as activity_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:layout_gravity="center_horizontal"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:max="100"
        android:minHeight="50dp"
        android:minWidth="200dp"
        android:progress="1" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Run Progress" />
</LinearLayout>

3.Copy the code in MainActivity.java. Activity.
packagein.ac.srmuniv.progressbartutorial1;

importandroid.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
importandroid.widget.Button;
importandroid.widget.ProgressBar;
importandroid.widget.TextView;
importandroid.view.View.OnClickListener;

public class MainActivity extends Activity {
     private ProgressBar progressBar;
     private int progressStatus = 0;
     private TextView textView;
     private Button clickButton;

     private Handler handler = new Handler();

     @Override
     protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
           progressBar = (ProgressBar) findViewById(R.id.progressbar);
           textView = (TextView) findViewById(R.id.textView1);
           clickButton = (Button) findViewById(R.id.button1);
           // ---0 - VISIBLE; 4 - INVISIBLE; 8 - GONE---
           progressBar.setVisibility(4);
           clickButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                     progressBar.setVisibility(0);
                     new Thread(new Runnable() {
                           public void run() {
                                while (progressStatus < 100) {

                                     progressStatus += 1;
                                     // Update the progress bar and display the
                                     // current value in the text view
                                     handler.post(new Runnable() {
                                           public void run() {
                                                progressBar.setProgress(progressStatus);
                                                textView.setText(progressStatus + "/"+ progressBar.getMax());
                                                if (progressStatus == 100) {
                                                     progressBar.setVisibility(8);
                                                     textView.setText("");

                                                }
                                           }
                                     });
                                     try {
                                           // Sleep for 100 milliseconds.
                                           // Just to display the progress slowly
                                           Thread.sleep(100);
                                     } catch(InterruptedException e) {
                                           e.printStackTrace();
                                     }

                                }
                                progressStatus = 0;
                           }

                     }).start();

                }
           });
           // Start long running operation in a background thread
     }
}
4.No need to modify Androidmanifest.xml
5.Run the application in the emulator. 

Figure 6 Shows Progress bar in action Figure 7 Shows Progress  bar is GONE and does not occupy space in Activity.


Figure 8 Shows Progress bar in Indeterminate mode Figure 9 Shows Progress bar in Indeterminate mode default cyclic action
CODE EXPLANATION
                  By default the progress bar will be displayed as a spinning wheel. If we want it to be displayed as a horizontal bar, we need to use  style="?android:attr/progressBarStyleHorizontal" attribute.
    <ProgressBar android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
       ......
      />By default the progress bar maximum value is 100. It can also be changed by setting the our own maximum value using android:max attribute.If we know the amount of work, then we can use this progress bar showing the actual progress. But if we do not know the amount of work to be done, then we can use  
progressBar.setIndeterminate(true);in the activity class programmatically or using 
android:indeterminate="true" in the layout xml file which will enable the intermediate mode. In the intermediate mode the actual progress will not be shown. A cyclic animation will be shown to indicate that some progress is happening. This intermediate mode is shown below.The difference between the INVISIBLE and GONE constants is that the INVISIBLE constant simply hides the ProgressBar view. The GONE constant removes the ProgressBar view from the activity and does not take up any space on the activity. 

Picker Views
Selecting date and time is one of the very common tasks you need to perform in a mobile application. Android supports this functionality through the TimePicker and DatePicker views.They use set of spinners to select the Time and date.In general these views are not directly used in layout of an Activity instead they are used with Dialogs infact DialogFragments.

DATE and TIME PICKER VIEWs

The date Picker view enables user to select valid date which has the set of spinners and the calendar view are automatically synchronizedThe TimePicker view enables users to select a time of the day, in either 24 Hour mode or AM/PM mode. You can use “android.widget.TimePicker” class to render a time picker component to select hour and minute in a pre-defined user interface.

The Demonstrative project portrays the Date/Time picker views
1.Create  Android project with details as listed in table below
Property name
Property value
Project name
SRM_DateTimePickerViewTutorial
Package name
in.ac.srmuniv.datetimepickertutorial
Activity name
MainActivity
Layout xml name
activity_main

2.Copy the code  to the file activity_main.xml in res/layout folder <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


    xmlns:tools="http://schemas.android.com/tools"


    android:layout_width="match_parent"


    android:layout_height="match_parent"


    android:orientation="vertical"


    android:paddingTop="@dimen/activity_vertical_margin"


    tools:context=".MainActivity" >




    <ScrollView


        android:layout_width="match_parent"


        android:layout_height="match_parent" >




        <LinearLayout


            android:layout_width="match_parent"


            android:layout_height="wrap_content"


            android:orientation="vertical" >




            <DatePicker


                android:id="@+id/pickerdate"


                android:layout_width="wrap_content"


                android:layout_height="wrap_content" />




            <TimePicker


                android:id="@+id/pickertime"


                android:layout_width="wrap_content"


                android:layout_height="wrap_content" />




            <TextView


                android:id="@+id/datetimeInfo"


                android:layout_width="match_parent"


                android:layout_height="wrap_content" />


        </LinearLayout>


    </ScrollView>




</LinearLayout>

3.Copy the code in MainActivity.java. Activity

packagein.ac.srmuniv.datetimepickertutorial;

import java.util.Calendar;
import android.os.Bundle;
importandroid.app.Activity;
importandroid.widget.DatePicker;
importandroid.widget.DatePicker.OnDateChangedListener;
importandroid.widget.TextView;
importandroid.widget.TimePicker;
importandroid.widget.TimePicker.OnTimeChangedListener;
importandroid.widget.Toast;

public class MainActivity extends Activity {

     DatePicker pickerDate;
     TimePicker pickerTime;
     TextView datetimeInfo;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);

           datetimeInfo = (TextView) findViewById(R.id.datetimeInfo);
           pickerDate = (DatePicker) findViewById(R.id.pickerdate);
           pickerTime = (TimePicker) findViewById(R.id.pickertime);

           Calendar now = Calendar.getInstance();

           pickerDate.init(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                     now.get(Calendar.DAY_OF_MONTH), newOnDateChangedListener() {

                           @Override
                           public voidonDateChanged(DatePicker view, int year,
                                     int monthOfYear, int dayOfMonth) {
                                Toast.makeText(getApplicationContext(),
                                           "onDateChanged", Toast.LENGTH_SHORT).show();

                                datetimeInfo.setText("Year: " + year + "\n"
                                           + "Month of Year: " + monthOfYear + "\n"
                                           + "Day of Month: " + dayOfMonth);

                           }
                     });

           pickerTime.setCurrentHour(now.get(Calendar.HOUR_OF_DAY));
           pickerTime.setCurrentMinute(now.get(Calendar.MINUTE));
           pickerTime.setOnTimeChangedListener(newOnTimeChangedListener() {

                @Override
                public voidonTimeChanged(TimePicker view, int hourOfDay, int minute) {
                     Toast.makeText(getApplicationContext(), "onTimeChanged",
                                Toast.LENGTH_SHORT).show();

                     datetimeInfo.setText("Hour of Day: " + hourOfDay + "\n"
                                + "Minute: " + minute);
                }
           });
     }

}

4.No need to modify Androidmanifest.xml
5.Run the application in the emulator. 


Figure 10: The date and Time picker view in ActivityFigure 11: The TimePicker in action when time is selected it is displayed in textview.
Figure 12: The DatePicker view in action with selected date displayed in textview
CODE EXPLANATION
The code uses java.util.Calender to set current date and time to the respective views.With the set of spinners used to select day.month and year OnDateChangedListener's
public void onDateChanged(DatePicker view, int year,                             int monthOfYear, int dayOfMonth)
method is called enables to fetch date in to the application.Similarly for TimePicker view OnTimeChangedListener takes care of fetching time in hours and minutes along with AM/PM.You can see these views occupy large screen space it is ideal to use Dialog box to pick date and time.

AnalogClock and DigitalClock Views

Analog clock & Digital Clock: Analog clock widget displays an analogic clock with two hands for hours and minutes. Digital clock widget displays an digital clock. You can set the width and height of the clock using the attributes available under AnalogClock and DigitalClock to suit your layout/ UI screen.
1.Create  Android project with details as listed in table below
Property name
Property value
Project name
SRM_ClockWidgetTutorial
Package name
in.ac.srmuniv.clockwidgettutorial
Activity name
MainActivity
Layout xml name
digitalanalogview
2.Copy the code  to the file activity_main.xml in res/layout folder 
<?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" >

    <AnalogClock
        android:id="@+id/clock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <DigitalClock
        android:id="@+id/clock2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</LinearLayout>

3.Copy the code in ClockExample.java. Activity.

package in.ac.srmuniv.clockwidgettutorial;
import android.app.Activity;
import android.os.Bundle;

public  class ClockExample extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public  void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.digitalanalogview);
    }

}
4.No need to modify Androidmanifest.xml
5.Run the application in the emulator. 
 Figure 2 shows the analog clock and the digital clock.

Figure 13 - The Analog/ DigitalClock view in action



Demikianlah Artikel Android UI Basic Views,Progressbar and Picker views Tutorial

Sekianlah artikel Android UI Basic Views,Progressbar and Picker views Tutorial kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel Android UI Basic Views,Progressbar and Picker views Tutorial dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/android-ui-basic-viewsprogressbar-and.html

Artikel Terkait

Android UI Basic Views,Progressbar and Picker views Tutorial
4/ 5
Oleh

Berlangganan

Suka dengan artikel di atas? Silakan berlangganan gratis via email