Download presentation
Presentation is loading. Please wait.
Published byLewis Simon Hines Modified over 9 years ago
1
User Interface Android Club 2015
2
Agenda Button OnClickListener OnLongClickListener ToggleButton Checkbox RatingBar AutoCompleteTextView
3
Button: example Button bButton = (Button) findViewById(R.id.bButton); bButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "Button click", Toast.LENGTH_LONG).show(); } });
4
Button: practice Add new button to your layout Set OnClickListener OnClick show Toast: “Hello Android!”
5
OnLongClickListener: example bButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getApplicationContext(), "Button long click", Toast.LENGTH_LONG).show(); return true; } });
6
OnLongClickListener: practice Set OnClickListener to the previous button you created OnLongClick show Toast: “Heeelloooo Aaaandrooooooiiiiiiiiid!”
7
ToggleButton: example final ToggleButton tbButton = (ToggleButton) findViewById(R.id.tbButton); tbButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = tbButton.isChecked(); if (checked) { tbButton.setText("Turned on"); } else { tbButton.setText("Turned off"); } } });
8
ToggleButton: practice Put ToggleButton Set onClickListener OnClick check isChecked or not If checked show text: Music is playing =) If not: Music is stopped =(
9
CheckBox: example final CheckBox cbPizza = (CheckBox) findViewById(R.id.cbPizza); cbPizza.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = cbPizza.isChecked(); if (checked) { Toast.makeText(getApplicationContext(),"Pizza with cheese", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),"Pizza without cheese", Toast.LENGTH_LONG).show(); } } });
10
CheckBox: practice Add CheckBox: Do you want to go to party? Set onClickListener If checked Toast: You go to party If not Toast: You do not go to party
11
RatingBar: example RatingBar rbPizza = (RatingBar) findViewById(R.id.rbPizza); rbPizza.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast.makeText(getApplicationContext(), "Pizza rating:"+rating, Toast.LENGTH_LONG).show(); } });
12
RatingBar: practice Create new RatingBar On rating change: Show Toast Example: “Party rating: 3”
13
AutoCompleteTextView: example AutoCompleteTextView actvStudents = (AutoCompleteTextView) findViewById(R.id.actvStudents); String[] students = {"Amirsaidkhon", "Nurislom", "Evgeniy","Kudrat","Yusuf","Samuil","Munis a","Nargiza","Ravshan"}; ArrayAdapter adapter = new ArrayAdapter (this,android.R.layout.sim ple_list_item_1,students); actvStudents.setAdapter(adapter);
14
AutoCompleteTextView: practice Create AutoComplete TextView Create cities String array Create ArrayAdapter Set adapter to AutoCompleteTextView
15
Hide/show view: example final ToggleButton tbRatingVisible = (ToggleButton) findViewById(R.id.tbRatingVisible); tbRatingVisible.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = tbRatingVisible.isChecked(); if (checked) { rbPizza.setVisibility(View.VISIBLE); tbRatingVisible.setText("Rating is visible"); } else { rbPizza.setVisibility(View.INVISIBLE); tbRatingVisible.setText("Rating is not visible"); } } });
16
Hide/show: practice Create another ToggleButton Set on click listener OnClick: show/hide AutoCompleteTextView
17
Qeustions? Any questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.