Android.Widgets       Tutorial 2 : Powering with Selection WidgetBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(...
Spinner– The resource poolSpinner is a widget similar to a drop down list selecting items. Here is the xml file        <?x...
Spinner– The resource pool                             Java File will contain following codepackage com.spinner;import and...
Spinner– The resource poolpublic void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentVie...
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           ...
GridView – Roar LouderGridView is a ViewGroup that displays items in a 2-D,scrollable grid. The grid items            get ...
GridView– Roar Louder               ..Continued from previous slide.<GridViewandroid:id="@+id/grid"android:layout_width="f...
GridView– Roar Louder                             Java File will contain following codepackage com.Grid;import android.app...
GridView– Roar Louder public void onCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R....
GridView– Roar Louder private class FunnyLookingAdapter extends ArrayAdapter {     Context ctxt;FunnyLookingAdapter(Contex...
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 .Sugg...
AutoComplete – Intelligence                    way                             Java File will contain following codepackag...
AutoComplete – Intelligence                    waypublic void onCreate(BundlesavedInstanceState) {super.onCreate(savedInst...
AutoComplete – Intelligence           wayThe following output is obtained when you run the code via emulator.
Thank you..GET IN TOUCH– Tune Up   RadioButton                               Phone:                               +91-9822...
Upcoming SlideShare
Loading in...5
×

Android Tutorials - Powering with Selection Widget

3,480

Published on

Android Tutorials By Prajyot Mainkar

Published in: Technology, Art & Photos
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,480
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Android Tutorials - Powering with Selection Widget

  1. 1. Android.Widgets Tutorial 2 : Powering with Selection WidgetBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(Hons.) Computer Engineering , PMP( IIT Delhi) S
  2. 2. 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>
  3. 3. 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
  4. 4. 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(""); } }
  5. 5. Spinner– The resource poolThe following output is obtained when you run the code via emulator.
  6. 6. Spinner– The resource poolThe following output is obtained when you run the code via emulator. The radio button can be replaced by checkboxes.
  7. 7. 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" />
  8. 8. 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>
  9. 9. 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"};
  10. 10. 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("");}
  11. 11. 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); } } }
  12. 12. GridView – Roar LouderThe following output is obtained when you run the code via emulator.
  13. 13. 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>
  14. 14. 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"};
  15. 15. 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 } }
  16. 16. AutoComplete – Intelligence wayThe following output is obtained when you run the code via emulator.
  17. 17. Thank you..GET IN TOUCH– Tune Up RadioButton Phone: +91-9822987513 facebook.com/prajyotmainkar Email: twitter.com/prajyotm prajyotm@msn.com

×