Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.guip;
- import android.app.Activity;
- import android.app.ActionBar;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.RatingBar;
- import android.widget.Toast;
- import android.os.Build;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- // SVAKO (KLASU) DETE MOZEMO DA GLEDAMO KAO (KLASU)
- // RODITELJA
- // View RODITELJ SVIH GUI ELEMENATA
- public void metoda1 (View element) {
- // CTRL + SHIFT + O
- // da li je kliknuto na button?
- // BUTTON JE DETE OD VIEW !!!!
- // ako jeste instanceof ce vratiti true
- // tada znamo da imamo button!
- if (element instanceof Button){
- Button elementKaoButton = (Button) element;
- Toast.makeText(getApplicationContext(),elementKaoButton.getText(), Toast.LENGTH_LONG).show();
- }
- }
- public void opisOcene (View element) {
- if (element instanceof RatingBar){
- RatingBar rb = (RatingBar) element;
- String opis;
- int brZvezda;
- brZvezda = rb.getNumStars();
- if (brZvezda == 5){
- opis = "Odlican!";
- } else if(brZvezda == 4){
- opis = "Vrlo dobar!";
- } else if (brZvezda == 3){
- opis = "Dobar!";
- } else if (brZvezda == 2){
- }
- Toast.makeText(getApplicationContext(), opis, Toast.LENGTH_LONG).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;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement