• Save
Android Tutorials : Basic widgets
Upcoming SlideShare
Loading in...5

Android Tutorials : Basic widgets



Tutorial 1 - Learning About Basic Widgets In Android

Tutorial 1 - Learning About Basic Widgets In Android



Total Views
Views on SlideShare
Embed Views



6 Embeds 55

http://a0.twimg.com 28
http://uzinadeganduri.ro 15
http://www.linkedin.com 8
https://www.linkedin.com 2
http://www.twylah.com 1
http://www.mefeedia.com 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Android Tutorials : Basic widgets Android Tutorials : Basic widgets Presentation Transcript

  • Android.Widgets Tutorial 1 : Empowering Android WidgetsBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(Hons.) Computer Engineering , PMP( IIT Delhi) S
  • 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" />
  • TextView – The Andro-LabelThe following output is obtained when you run the code via emulator.
  • 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.
  • Images – Fleeting with images The following output is obtained when you run the code via emulator.
  • 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" />
  • 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"); }}
  • 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" />
  • 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"); } } }
  • CheckBox – Lets *Check*The following output is obtained when you run the code via emulator.
  • 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
  • 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>
  • Thank you..GET IN TOUCH– Tune Up RadioButton Phone: +91-9822987513 facebook.com/prajyotmainkar Email: twitter.com/prajyotm prajyotm@msn.com