Wednesday, 24 July 2019

Android rating bar


import android.os.Bundle;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.view.*;
import android.widget.Button; 
import android.widget.RatingBar; 
import android.widget.Toast; 

public class MainActivity extends Activity {
RatingBar r1;
Button b1;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              addListenerOnButtonClick(); 
       }

        public void addListenerOnButtonClick(){ 
               r1=(RatingBar)findViewById(R.id.ratingBar1); 
               b1=(Button)findViewById(R.id.button1); 
               //Performing action on Button Click 
               b1.setOnClickListener(new OnClickListener(){ 
        
                   @Override 
                   public void onClick(View arg0) { 
                       //Getting the rating and displaying it on the toast 
                       String rating=String.valueOf(r1.getRating()); 
                       Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show(); 
                   } 
                    
               }); 
           } 
} 

No comments:

Post a Comment