如何将 ratingStars 更改为字符串?
我试图将 RatingBar numOfStar() 方法转换为字符串而不是 int。试图做 numOfStar().ToString 但这是不可能的。
我该怎么做呢?因为我想将它作为字符串保存在 SQLite 数据库中。
public RatingBar ratingbar;
ratingbar = (RatingBar)findViewById(R.id.ratingBar1);
private void saveState(){
book_name = title.getText().toString();
author = book_author.getText().toString();
isbn = isbn_number.getText().toString();
if(mRowId == null){
long id = mDbHelper.addBook(book_name, author, isbn, ratings);
if(id > 0 ){
mRowId = id;
}
}else{
mDbHelper.updateBooks(mRowId, book_name, author, ratings, isbn);
}
Im trying to translate RatingBar numOfStar() method into a string instead of an int. In tried to do numOfStar().ToString and it isnt possible.
How can i go about doing this. Because i want to save it as a string in SQLite database.
public RatingBar ratingbar;
ratingbar = (RatingBar)findViewById(R.id.ratingBar1);
private void saveState(){
book_name = title.getText().toString();
author = book_author.getText().toString();
isbn = isbn_number.getText().toString();
if(mRowId == null){
long id = mDbHelper.addBook(book_name, author, isbn, ratings);
if(id > 0 ){
mRowId = id;
}
}else{
mDbHelper.updateBooks(mRowId, book_name, author, ratings, isbn);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
String.valueOf(Ratingbar.getRating())
ratingbar.setRating(Float.valueOf(“某个字符串”))
String.valueOf(ratingbar.getRating())
ratingbar.setRating(Float.valueOf("some string"))
我可能需要查看更多代码,以便了解 RatingBar numOfStar 的定义,尽管 Java 中的 toString 方法以小写“t”开头,这一点很重要,因为 Java 区分大小写。
I may need to see some more code so that I know what RatingBar numOfStar is defined as, although the toString method in Java starts with a lower case 't' which is important as Java is case-sensitive.
使用
String.valueOf(value)
将基本类型转换为字符串。Use
String.valueOf(value)
to convert a primitive type to a String.