Advertisement
kernel_memory_dump

RatingBar

Apr 11th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. package com.example.guip;
  2.  
  3. import android.app.Activity;
  4. import android.app.ActionBar;
  5. import android.app.Fragment;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.RatingBar;
  13. import android.widget.RatingBar.OnRatingBarChangeListener;
  14. import android.widget.Toast;
  15. import android.os.Build;
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.         RatingBar rb;
  24.     rb = (RatingBar) findViewById (R.id.ratingBar1);
  25.     rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
  26.          @Override
  27.         public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
  28.             opisOcene(ratingBar);
  29.         }
  30.     });
  31.      
  32.     }
  33.  
  34.     // SVAKO  (KLASU) DETE MOZEMO DA GLEDAMO KAO  (KLASU)
  35.     // RODITELJA
  36.     //  View RODITELJ SVIH GUI ELEMENATA
  37.    
  38.     public void metoda1 (View element) {
  39.         // CTRL + SHIFT + O
  40.         // da li je kliknuto na button?
  41.         // BUTTON JE DETE OD VIEW !!!!
  42.         // ako jeste instanceof ce vratiti true
  43.         // tada znamo da imamo button!
  44.        
  45.         if (element instanceof Button){
  46.             Button elementKaoButton = (Button) element;
  47.             Toast.makeText(getApplicationContext(),elementKaoButton.getText(), Toast.LENGTH_LONG).show();
  48.         }
  49.     }
  50.    
  51.     public void opisOcene (RatingBar rb) {
  52.         Toast.makeText(getApplicationContext(), "Pozvana metoda!", Toast.LENGTH_LONG).show();
  53.             String opis = "";
  54.             int brZvezda;
  55.            
  56.             brZvezda = rb.getNumStars();
  57.             brZvezda = (int)rb.getRating();
  58.             if (brZvezda == 5){
  59.                 opis = "Odlican!";
  60.             } else if(brZvezda == 4){
  61.                 opis = "Vrlo dobar!";
  62.             } else if (brZvezda == 3){
  63.                 opis = "Dobar!";
  64.             } else if (brZvezda == 2){
  65.                 opis = "Dovoljan";
  66.             } else if (brZvezda == 1){
  67.                 opis = "Nedovoljan";
  68.             } else {
  69.                 opis = "???????";
  70.             }
  71.            
  72.             Toast.makeText(getApplicationContext(), opis, Toast.LENGTH_LONG).show();
  73.         }
  74.        
  75.    
  76.    
  77.  
  78.     @Override
  79.     public boolean onCreateOptionsMenu(Menu menu) {
  80.        
  81.         // Inflate the menu; this adds items to the action bar if it is present.
  82.         getMenuInflater().inflate(R.menu.main, menu);
  83.         return true;
  84.     }
  85.  
  86.     @Override
  87.     public boolean onOptionsItemSelected(MenuItem item) {
  88.         // Handle action bar item clicks here. The action bar will
  89.         // automatically handle clicks on the Home/Up button, so long
  90.         // as you specify a parent activity in AndroidManifest.xml.
  91.         int id = item.getItemId();
  92.         if (id == R.id.action_settings) {
  93.             return true;
  94.         }
  95.         return super.onOptionsItemSelected(item);
  96.     }
  97.  
  98.  
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement