Your SlideShare is downloading. ×
Android Tutorials : Basic widgets
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Android Tutorials : Basic widgets

7,959
views

Published on

Tutorial 1 - Learning About Basic Widgets In Android

Tutorial 1 - Learning About Basic Widgets In Android

Published in: Technology

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,959
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Android.Widgets Tutorial 1 : Empowering Android WidgetsBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(Hons.) Computer Engineering , PMP( IIT Delhi) S
  • 2. TextView – The Andro-Label The simplest widget is the label, referred to in Android as a TextView . Typically, these are used like labels in Android UICreate a new android project with following contents in main.xml and run this project on emulator <?xml version="1.0" encoding="utf-8"?> <TextViewxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is sample demo of TextView" />
  • 3. TextView – The Andro-LabelThe following output is obtained when you run the code via emulator.
  • 4. Images – Fleeting with imagesAndroid has two widgets to help embed images in your activities: ImageViewand ImageButton. As the names suggest, they are image-based analogues to TextView and Button , respectively. <?xml version="1.0" encoding="utf-8"?> <ImageViewxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:src="@drawable/logo" /> Note that, android:src takes path of image from the drawable folder(@ is the reference), so drag „n drop /paste any logo.png image to drawable folder.
  • 5. Images – Fleeting with images The following output is obtained when you run the code via emulator.
  • 6. EditText– Learning EditTextEditText is a thin veneer over TextView that configures itself to be editable. In the javafile (Src folder) import the file “import android.widget.EditText;”. Find the xml code below <?xml version="1.0" encoding="utf-8"?> <EditTextxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/editfield" android:layout_width="fill_parent" android:layout_height="fill_parent" android:singleLine="false" />
  • 7. EditText – Learning EditTextpackage com.EditTextDemo;import android.app.Activity;import android.os.Bundle;import android.widget.EditText;public class EditTextDemoActivity extends Activity { /** Called when the activity is first created. */@OverrideEditText E; public void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);E.setText("This is sample edit text demo"); }}
  • 8. CheckBox– Lets *Check*•isChecked(): Determines if the check box has been checked.•setChecked(): Forces the check box into a checked or unchecked•state.•toggle(): Toggles the check box as if the user checked it. <?xml version="1.0" encoding="utf-8"?> <CheckBoxxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This checkbox is unchecked" />
  • 9. CheckBox – Lets *Check*package com.CheckBoxDemo;import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;public class CheckBoxDemoActivity extends Activity implements CompoundButton.OnCheckedChangeListener {CheckBox checkbox;public void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main); checkbox=(CheckBox)findViewById(R.id.checkbox);checkbox.setOnCheckedChangeListener(this); }public void onCheckedChanged(CompoundButtonbuttonView,booleanisChecked) {if (isChecked) {checkbox.setText("This checkbox is: checked");}else {checkbox.setText("This checkbox is: unchecked"); } } }
  • 10. CheckBox – Lets *Check*The following output is obtained when you run the code via emulator.
  • 11. RadioButton – Tune Up •check(): Checks a specific radio button via its ID •clearCheck(): Clears all radio buttons, so none in the group are checked.•getCheckedRadioButtonId(): Gets the ID of the currently checked radio button (or -1 if none are checked). Most times RadioButton widgets are placed inside a RadioGroup . The RadioGroup indicates a set of radio buttons whose state is tied, meaning only one button in that group can be selected at any time. If you assign an android:id to yourRadioGroup in your XML layout, you can access the group from your Java code and
  • 12. RadioButton – Tune Up•The XML Code is below. Make no changes to Java File : <?xml version="1.0" encoding="utf-8"?> <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Goa" /> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Maharashtra" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Kerala" /> </RadioGroup>
  • 13. Thank you..GET IN TOUCH– Tune Up RadioButton Phone: +91-9822987513 facebook.com/prajyotmainkar Email: twitter.com/prajyotm prajyotm@msn.com