-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
52 lines (44 loc) · 1.57 KB
/
MainActivity.java
File metadata and controls
52 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.familia.ratingbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RatingBar ratingBar;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "stars: " + (int)ratingBar.getNumStars(),Toast.LENGTH_LONG).show();
}
});}
public int getStars (int stars){
int salida = 0 ;
int presalida = 0;
double starsnumber;
starsnumber = (int)ratingBar.getNumStars();
if (starsnumber == 1){
presalida = 1;
} else if (starsnumber == 2) {
presalida = 2;
} else if (starsnumber == 3) {
presalida = 3;
}
else if (starsnumber == 4){
presalida = 4;
}
else if (starsnumber == 5) {
presalida = 5;
}
salida = presalida + salida;
return salida;
}
}