Android 评级栏在自定义对话框中不起作用,在调试器中显示排序栏:null(值)?
public static float i=0;
public static String tst;
private RatingBar ratingBar;
private Dialog dialog;
private Button dialog_btn;
//这里继续创建方法等..
protected Dialog onCreateDialog(int id)
{
dialog = new Dialog(this);
dialog.setContentView(R.layout.customdialog);
dialog.setTitle("Рејтинг");
ratingBar = (RatingBar) findViewById(R.id.ratingbarD);
dialog_btn = (Button) dialog.findViewById(R.id.rank_dialog_button);
dialog_btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
i=ratingBar.getRating();
tst=Float.toString(i);
Toast.makeText(vicp.this,tst,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
return dialog;
}
//我有自定义对话框的xml,上面有评级栏和按钮,我得到的错误是在线的(i = ratingbar.getRating();)
public static float i=0;
public static String tst;
private RatingBar ratingBar;
private Dialog dialog;
private Button dialog_btn;
//here goes onCreate metod etc..
protected Dialog onCreateDialog(int id)
{
dialog = new Dialog(this);
dialog.setContentView(R.layout.customdialog);
dialog.setTitle("Рејтинг");
ratingBar = (RatingBar) findViewById(R.id.ratingbarD);
dialog_btn = (Button) dialog.findViewById(R.id.rank_dialog_button);
dialog_btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
i=ratingBar.getRating();
tst=Float.toString(i);
Toast.makeText(vicp.this,tst,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
return dialog;
}
//i have xml for customdialog and on it rating bar and button, the error i get is on line(i=ratingbar.getRating();)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有忘记在对话框上执行 findViewById() 吗?换句话说,不应该是:
Didn't you forget to do the findViewById() on the dialog? In other words, shouldn't it be: