我有一个显示评分栏的警报对话框。
LayoutInflater rating = LayoutInflater.from(RatingActivity.this);
final View v = rating.inflate(R.layout.rating_layout, null);
AlertDialog.Builder adb = new AlertDialog.Builder(RatingActivity.this);
adb.setTitle("Rate us!);
adb.setView(v);
AlertDialog ratingbar = adb.create();
final RatingBar cleanbar = (RatingBar) ratingbar.findViewById(R.id.clealiness);
当我触发 onclick 监听器时,它显示 NULL POINTER EXCEPTION。第二行错误表示 getNumStars() 行中的错误。之后强制关闭。
adb.setPositiveButton("Rate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//this line error. means they cant get the rating value?
final String cleaninput = Integer.toString(cleanbar.getNumStars());
我可以知道任何其他方法来获得评级栏的价值吗?我见过很少有人喜欢 ratingBar.getRating(); ratingBar.getNumStars();
他们都无法工作......即使我将值直接放入int。
final int cleaninput = (int) cleanbar.getRating(); //fails
编辑(解决)::
final RatingBar cleanbar = (RatingBar)v.findViewById(R.id.clealiness);
我将评级栏替换为 v 并且它有效!不知道是什么原因>.<