• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android Tutorials - Powering with Selection Widget
 

Android Tutorials - Powering with Selection Widget

on

  • 3,575 views

Android Tutorials By Prajyot Mainkar

Android Tutorials By Prajyot Mainkar

Statistics

Views

Total Views
3,575
Views on SlideShare
3,566
Embed Views
9

Actions

Likes
3
Downloads
0
Comments
0

3 Embeds 9

http://www.androcid.com 4
http://www.linkedin.com 3
http://a0.twimg.com 2

Accessibility

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.

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

    Android Tutorials - Powering with Selection Widget Android Tutorials - Powering with Selection Widget Presentation Transcript

    • Android.Widgets Tutorial 2 : Powering with Selection WidgetBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(Hons.) Computer Engineering , PMP( IIT Delhi) S
    • Spinner– The resource poolSpinner is a widget similar to a drop down list selecting items. Here is the xml file <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/selection" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="true" /> </LinearLayout>
    • Spinner– The resource pool Java File will contain following codepackage com.spinner;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;import android.widget.TextView;public class SpinnerActivity extends Activity implementsAdapterView.OnItemSelectedListener {TextView selection;String[] items={"Prajyot", "Prakash", "Mainkar"};//Continued on next slide
    • Spinner– The resource poolpublic void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main); selection=(TextView)findViewById(R.id.selection); Spinner spin=(Spinner)findViewById(R.id.spinner);spin.setOnItemSelectedListener(this);ArrayAdapter<String>aAdapter=newArrayAdapter<String>(this,android.R.layout.simple_spinner_item, items);aAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spin.setAdapter(aAdapter); }public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {selection.setText(items[position]); }public void onNothingSelected(AdapterView<?> parent) {selection.setText(""); } }
    • Spinner– The resource poolThe following output is obtained when you run the code via emulator.
    • Spinner– The resource poolThe following output is obtained when you run the code via emulator. The radio button can be replaced by checkboxes.
    • GridView – Roar LouderGridView is a ViewGroup that displays items in a 2-D,scrollable grid. The grid items get inserted automatically to the layout using a ListAdapter <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/selection" android:layout_width="fill_parent" android:layout_height="wrap_content" />
    • GridView– Roar Louder ..Continued from previous slide.<GridViewandroid:id="@+id/grid"android:layout_width="fill_parent"android:layout_height="fill_parent"android:verticalSpacing="40px"android:horizontalSpacing="10px"android:numColumns="auto_fit"android:columnWidth="100px"android:stretchMode="columnWidth"android:gravity="center"/></LinearLayout>
    • GridView– Roar Louder Java File will contain following codepackage com.Grid;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.GridView;import android.widget.TextView;public class GridActivity extends Activity implements AdapterView.OnItemSelectedListener {TextView selection; String[] items={"Goa", "Maharashtra", "TamilNadu", "Rajasthan", "Gujrat", "MP", "Karnataka", "Kerala", "Delhi", "AndraPradesh", "Assam", "Manipur", "Orissa", "Punjab", "J&K", "Himachal Pradesh", "West Bengal", "Tripura", "Uttarakhand", "Sikkim", "Bihar", "ArunachalP", "Chhattisgarh", "D&D", "Pondicherry"};
    • GridView– Roar Louder public void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);selection=(TextView)findViewById(R.id.selection);GridViewg=(GridView) findViewById(R.id.grid);g.setAdapter(newFunnyLookingAdapter(this, android.R.layout.simple_list_item_1,items));g.setOnItemSelectedListener(this); } public void onItemSelected(AdapterView<?> parent, View v,int position, long id) {selection.setText(items[position]); } public void onNothingSelected(AdapterView<?> parent) {selection.setText("");}
    • GridView– Roar Louder private class FunnyLookingAdapter extends ArrayAdapter { Context ctxt;FunnyLookingAdapter(Contextctxt, int resource, String[] items) {super(ctxt, resource, items);this.ctxt=ctxt; } public View getView(int position, View convertView,ViewGroup parent) {TextView label=(TextView)convertView; if (convertView==null) {convertView=new TextView(ctxt); label=(TextView)convertView; }label.setText(items[position]);return(convertView); } } }
    • GridView – Roar LouderThe following output is obtained when you run the code via emulator.
    • AutoComplete – Intelligence way Allows to suggest the remaining text-type using the intelligent way .Suggestions arereceived from a collection of strings associated with the widget through ArrayAdapter <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" > <TextView android:id="@+id/selection" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="States" /> <AutoCompleteTextViewandroid:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="3"/> </LinearLayout>
    • AutoComplete – Intelligence way Java File will contain following codepackage com.AutoComplete;import android.app.Activity;import android.os.Bundle;import android.text.Editable;import android.text.TextWatcher;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.TextView;public class AutoCompleteActivity extends Activity implements TextWatcher {TextView selection;AutoCompleteTextView edit;String[] items={"Goa", "Maharashtra", "TamilNadu", "Rajasthan", "Gujrat","MP", "Karnataka", "Kerala", "Delhi", "AndraPradesh","Assam", "Manipur", "Orissa", "Punjab", "J&K","Himachal Pradesh", "West Bengal", "Tripura", "Uttarakhand", "Sikkim","Bihar", "ArunachalP", "Chhattisgarh", "D&D", "Pondicherry"};
    • AutoComplete – Intelligence waypublic void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main); selection=(TextView)findViewById(R.id.selection); edit=(AutoCompleteTextView)findViewById(R.id.edit);edit.addTextChangedListener(this);edit.setAdapter(newArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, items)); }public void onTextChanged(CharSequences, int start, int before,int count) {selection.setText(edit.getText()); }public void beforeTextChanged(CharSequences, int start,int count, int after) { // used in case if interface }public void afterTextChanged(Editables) { // used in case if interface } }
    • AutoComplete – Intelligence wayThe following output is obtained when you run the code via emulator.
    • Thank you..GET IN TOUCH– Tune Up RadioButton Phone: +91-9822987513 facebook.com/prajyotmainkar Email: twitter.com/prajyotm prajyotm@msn.com