I have tried to adding rating bar which have stars to do rating, I want make the rate have 4 stars, but in my code I get more than 7 stars and when I tried to click on a star then appear double.. (for example: I click star 1 then display 2 stars selected)..
my Example:
My Code:
public class test extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
textView =(TextView)findViewById(R.id.textView1);
// Button1
final Button btn1 = (Button) findViewById(R.id.btnAddHotelRate);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ShowDialog();
}
});
}
public void ShowDialog()
{
final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
final RatingBar rating = new RatingBar(this);
rating.setMax(4);
popDialog.setIcon(android.R.drawable.btn_star_big_on);
popDialog.setTitle("Add Rating: ");
popDialog.setView(rating);
// Button OK
popDialog.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
textView.setText(String.valueOf(rating.getProgress()));
dialog.dismiss();
}
})
// Button Cancel
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
popDialog.create();
popDialog.show();
}
}
