Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make RatingBar in android ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 157
    Comment on it

    Here I have created RatingBar function in android. In android RatingBar can be used to get the rating from the user, it is also used for creating RatingBar. Below code example will described you how to make RatingBar function in Android.
    Step(1)- activity_main.xml

    1. <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. tools:context=".MainActivity" >
    6.  
    7. <RatingBar
    8. android:id="@+id/ratingBar1"
    9. android:layout_width="wrap_content"
    10. android:layout_height="wrap_content"
    11. android:layout_alignParentTop="true"
    12. android:layout_centerHorizontal="true"
    13. android:layout_marginTop="44dp" />
    14.  
    15. <Button
    16. android:id="@+id/button1"
    17. android:layout_width="wrap_content"
    18. android:layout_height="wrap_content"
    19. android:layout_alignLeft="@+id/ratingBar1"
    20. android:layout_below="@+id/ratingBar1"
    21. android:layout_marginLeft="92dp"
    22. android:layout_marginTop="66dp"
    23. android:text="submit" />
    24.  
    25. </RelativeLayout>

    Step(2)-Activity class-

    1. public class MainActivity extends Activity {
    2. RatingBar ratingbar1;
    3. Button button;
    4. @Override
    5. protected void onCreate(Bundle savedInstanceState) {
    6. super.onCreate(savedInstanceState);
    7. setContentView(R.layout.activity_main);
    8. addListenerOnButtonClick();
    9. }
    10.  
    11. public void addListenerOnButtonClick(){
    12. ratingbar1=(RatingBar)findViewById(R.id.ratingBar1);
    13. button=(Button)findViewById(R.id.button1);
    14. //Performing action on Button Click
    15. button.setOnClickListener(new OnClickListener(){
    16.  
    17. @Override
    18. public void onClick(View arg0) {
    19. String rating=String.valueOf(ratingbar1.getRating());
    20. Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show();
    21. }
    22.  
    23. });
    24. }
    25. @Override
    26. public boolean onCreateOptionsMenu(Menu menu) {
    27. getMenuInflater().inflate(R.menu.activity_main, menu);
    28. return true;
    29. }
    30.  
    31. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: