• Save
Android Tutorials - Powering with Selection Widget
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Android Tutorials - Powering with Selection Widget

  • 4,020 views
Uploaded on

Android Tutorials By Prajyot Mainkar

Android Tutorials By Prajyot Mainkar

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,020
On Slideshare
4,010
From Embeds
10
Number of Embeds
4

Actions

Shares
Downloads
0
Comments
0
Likes
3

Embeds 10

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

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 2 : Powering with Selection WidgetBy: Mr.PrajyotMainkarMS Software Systems( BITS-Pilani)BE(Hons.) Computer Engineering , PMP( IIT Delhi) S
  • 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. 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. 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. Spinner– The resource poolThe following output is obtained when you run the code via emulator.
  • 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. 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. 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. 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. 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. 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. GridView – Roar LouderThe following output is obtained when you run the code via emulator.
  • 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. 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. 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. AutoComplete – Intelligence wayThe following output is obtained when you run the code via emulator.
  • 17. Thank you..GET IN TOUCH– Tune Up RadioButton Phone: +91-9822987513 facebook.com/prajyotmainkar Email: twitter.com/prajyotm prajyotm@msn.com