I am having some logic problem with my Java code to prompt dialogue box. So basically when my ratingBar is onTouch, I will get the star rate and prompt dialogue box:
ratingBar.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View view, MotionEvent event)
{
float touchPositionX = event.getX();
float width = ratingBar.getWidth();
float starsf = (touchPositionX / width) * 5.0f;
starRate = (int)starsf + 1;
ratingBar.setRating(starRate);
promptSubmitStar();
return true;
}
});
public void promptSubmitStar(){
AlertDialog.Builder Dialog = new AlertDialog.Builder(getActivity());
Dialog.setTitle("Confirm Rating");
LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = li.inflate(R.layout.option_submit_star, null);
txtPromptStarRate = (TextView) dialogView.findViewById(R.id.txtPromptStarRate);
txtPromptStarRate.setText("Confirm to submit " + starRate + " stars for this event?");
Dialog.setView(dialogView);
Dialog.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
});
Dialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
});
Dialog.show();
}
But with these codes, when user selected the star rate, the dialogue box prompted twice. I wonder which part is causing it. Thanks in advance.