SlideShare a Scribd company logo
1 of 5
AutocompleteTextView
package example.aautocompletetextview;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
AutoCompleteTextView autocompletetextview;
String[] arr = { "MS SQL SERVER", "MySQL", "Oracle" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autocompletetextview = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter
(this,android.R.layout.select_dialog_item, arr);
autocompletetextview.setThreshold(1);
autocompletetextview.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/* Inflate the menu; this adds items to the action bar if
it is present */
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Spinner
import java.util.ArrayList;
import java.util.List;
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.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
public class AndroidSpinnerExampleActivity extends Activity implements OnItem
SelectedListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Business Services");
categories.add("Computers");
categories.add("Education");
categories.add("Personal");
categories.add("Travel");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinn
er_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
@Override
public void onItemSelected(AdapterView<?> parent, View
view, int position, long id) {
// On selecting a spinner item
String item = parent.getItemAtPosition(position).toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "Selected: " + item,
Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Toggle Button
package example.atogglebutton;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
private ToggleButton toggleBtn1, toggleBtn2;
private Button btResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnToggleButton();
}
private void addListenerOnToggleButton() {
toggleBtn1 = (ToggleButton) findViewById
(R.id.toggleButton1);
toggleBtn2 = (ToggleButton) findViewById
(R.id.toggleButton2);
btResult = (Button) findViewById(R.id.button1);
btResult.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("START Condition - ").append
(toggleBtn1.getText());
result.append("nSTOP Condition - ").append
(toggleBtn2.getText());
Toast.makeText(MainActivity.this, result.toString(),
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/* Inflate the menu; this adds items to the action bar
if it is present */
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Android AutocompleteTextView, Spinner and Toggle Button Examples

More Related Content

What's hot

Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.netGirija Muscut
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netGirija Muscut
 
Windows 10 - one application for all platforms. (UA Mobile 2016)
Windows 10 - one application for all platforms. (UA Mobile 2016)Windows 10 - one application for all platforms. (UA Mobile 2016)
Windows 10 - one application for all platforms. (UA Mobile 2016)Mykyta Bondarenko
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesCumulations Technologies
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaBabacar NIANG
 
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.Windows 10 - одно приложение для всех платформ. UA Mobile 2016.
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.UA Mobile
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...Ben Teese
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass SlidesNir Kaufman
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycleSV.CO
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint dataVladimir Medina
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentVladimir Medina
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)Brian Swartzfager
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Kirill Rozov
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Kirill Rozov
 

What's hot (19)

Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.net
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.net
 
Windows 10 - one application for all platforms. (UA Mobile 2016)
Windows 10 - one application for all platforms. (UA Mobile 2016)Windows 10 - one application for all platforms. (UA Mobile 2016)
Windows 10 - one application for all platforms. (UA Mobile 2016)
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations Technologies
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.Windows 10 - одно приложение для всех платформ. UA Mobile 2016.
Windows 10 - одно приложение для всех платформ. UA Mobile 2016.
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
View controller life cycle
View controller life cycleView controller life cycle
View controller life cycle
 
C#
C#C#
C#
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
React 101
React 101React 101
React 101
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1Why Kotlin - Apalon Kotlin Sprint Part 1
Why Kotlin - Apalon Kotlin Sprint Part 1
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 

Viewers also liked

Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011Birkbeck Babylab
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1aa11bb11
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Java assgn
Java assgnJava assgn
Java assgnaa11bb11
 
Course plan computer graphics
Course plan computer graphicsCourse plan computer graphics
Course plan computer graphicsaa11bb11
 
Course plan computer graphics lab
Course plan computer graphics labCourse plan computer graphics lab
Course plan computer graphics labaa11bb11
 
Graphics devices
Graphics devicesGraphics devices
Graphics devicesaa11bb11
 
Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1aa11bb11
 
Graphics pdf
Graphics pdfGraphics pdf
Graphics pdfaa11bb11
 

Viewers also liked (17)

Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1
 
lesson - Patient Safety and Spanish in the Pharmacy - to post
lesson - Patient Safety and Spanish in the Pharmacy - to postlesson - Patient Safety and Spanish in the Pharmacy - to post
lesson - Patient Safety and Spanish in the Pharmacy - to post
 
Opioids to Minors and Drug Donation Programs - lesson
Opioids to Minors and Drug Donation Programs - lessonOpioids to Minors and Drug Donation Programs - lesson
Opioids to Minors and Drug Donation Programs - lesson
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Java assgn
Java assgnJava assgn
Java assgn
 
REMS in the Community Pharmacy - lesson to Post
REMS in the Community Pharmacy - lesson to PostREMS in the Community Pharmacy - lesson to Post
REMS in the Community Pharmacy - lesson to Post
 
1. Title pages
1. Title pages1. Title pages
1. Title pages
 
Lect14
Lect14Lect14
Lect14
 
Aplikom
AplikomAplikom
Aplikom
 
Course plan computer graphics
Course plan computer graphicsCourse plan computer graphics
Course plan computer graphics
 
Course plan computer graphics lab
Course plan computer graphics labCourse plan computer graphics lab
Course plan computer graphics lab
 
Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
The stuarts
The stuartsThe stuarts
The stuarts
 
Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1
 
Graphics pdf
Graphics pdfGraphics pdf
Graphics pdf
 
B spline
B splineB spline
B spline
 

Similar to Android AutocompleteTextView, Spinner and Toggle Button Examples

Guardar Android
Guardar AndroidGuardar Android
Guardar AndroidyumiA1
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalDroidcon Berlin
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 
Rohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit malav
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design PatternsGodfrey Nolan
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Alfredo Morresi
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)Yurii Kotov
 

Similar to Android AutocompleteTextView, Spinner and Toggle Button Examples (20)

Androidppt 1
Androidppt 1Androidppt 1
Androidppt 1
 
F2
F2F2
F2
 
HNUH
HNUHHNUH
HNUH
 
20 Codigos
20 Codigos20 Codigos
20 Codigos
 
20 códigos de eclipse
20 códigos de eclipse20 códigos de eclipse
20 códigos de eclipse
 
Programa 2
Programa 2Programa 2
Programa 2
 
Guardar Android
Guardar AndroidGuardar Android
Guardar Android
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
Hola mundo12
Hola mundo12Hola mundo12
Hola mundo12
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
20 codigos
20 codigos20 codigos
20 codigos
 
Rohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan viharRohit android lab projects in suresh gyan vihar
Rohit android lab projects in suresh gyan vihar
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 

Android AutocompleteTextView, Spinner and Toggle Button Examples

  • 1. AutocompleteTextView package example.aautocompletetextview; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { AutoCompleteTextView autocompletetextview; String[] arr = { "MS SQL SERVER", "MySQL", "Oracle" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); autocompletetextview = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); ArrayAdapter adapter = new ArrayAdapter (this,android.R.layout.select_dialog_item, arr); autocompletetextview.setThreshold(1); autocompletetextview.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { /* Inflate the menu; this adds items to the action bar if it is present */ getMenuInflater().inflate(R.menu.main, menu); return true; } }
  • 2. Spinner import java.util.ArrayList; import java.util.List; 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.Toast; import android.widget.AdapterView.OnItemSelectedListener; public class AndroidSpinnerExampleActivity extends Activity implements OnItem SelectedListener{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Spinner element Spinner spinner = (Spinner) findViewById(R.id.spinner); // Spinner click listener spinner.setOnItemSelectedListener(this); // Spinner Drop down elements List<String> categories = new ArrayList<String>(); categories.add("Automobile"); categories.add("Business Services"); categories.add("Computers"); categories.add("Education"); categories.add("Personal"); categories.add("Travel"); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinn er_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // On selecting a spinner item String item = parent.getItemAtPosition(position).toString(); // Showing selected spinner item
  • 3. Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }
  • 4. Toggle Button package example.atogglebutton; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import android.widget.ToggleButton; public class MainActivity extends Activity { private ToggleButton toggleBtn1, toggleBtn2; private Button btResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); addListenerOnToggleButton(); } private void addListenerOnToggleButton() { toggleBtn1 = (ToggleButton) findViewById (R.id.toggleButton1); toggleBtn2 = (ToggleButton) findViewById (R.id.toggleButton2); btResult = (Button) findViewById(R.id.button1); btResult.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { StringBuffer result = new StringBuffer(); result.append("START Condition - ").append (toggleBtn1.getText()); result.append("nSTOP Condition - ").append (toggleBtn2.getText()); Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { /* Inflate the menu; this adds items to the action bar if it is present */ getMenuInflater().inflate(R.menu.main, menu); return true; } }