Android:RatingBar - 如何向数据库添加评级?

发布于 2024-11-08 15:45:36 字数 1098 浏览 0 评论 0原文

菜鸟又来了。

我遵循了 Google Dev 给出的示例(并阅读了一些其他教程),了解如何将评级栏添加到您的表单/应用程序中。然而,我无法在网上找到任何示例,说明如何获取给定的评级并将其作为值添加到 SQLite 数据库中。

目前,您只需在 EditText 字段中输入数字即可添加自己的评级。然而这并不理想,RatingBar 似乎是一个更理想的解决方案。我怀疑它与 OnClick() 有关,但我不完全确定我是初学者。

有什么想法吗?

评级栏:

final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
        ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { 
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Toast.makeText(AddBook.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();

        }
    });

添加行:

db.addRow
        (

                textFieldOne.getText().toString(),
                textFieldTwo.getText().toString(),
                textFieldThree.getText().toString(),
                textFieldFour.getText().toString(),
                textFieldFive.getText().toString(),
                textFieldSix.getText().toString()





        );

        // request the table be updated
        updateTable();

Noob here again.

I've followed the example given by Google Dev (and read a couple of other tutorials) on how to add a RatingBar to your form/app. However I have been unable to find any examples on the net, of how to take the Rating given and add it as a value to your SQLite database.

Currently you can add your own rating by simply putting a number in an EditText field. However this is not ideal, and the RatingBar seems like a more ideal solution. I suspect it has something to do with OnClick() but Im not entirely sure being a beginner.

Any ideas?

RatingBar:

final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
        ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { 
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Toast.makeText(AddBook.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();

        }
    });

AddRow:

db.addRow
        (

                textFieldOne.getText().toString(),
                textFieldTwo.getText().toString(),
                textFieldThree.getText().toString(),
                textFieldFour.getText().toString(),
                textFieldFive.getText().toString(),
                textFieldSix.getText().toString()





        );

        // request the table be updated
        updateTable();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏剧牡丹亭 2024-11-15 15:45:36

假设您有一个应用程序。

让我们进一步假设您有一个用户。

让我们继续讨论这个问题,假设您在应用程序中有一个活动,用户将在其中填写数据,并且目标是让这些数据最终进入 SQLite 数据库。

在某个地方,以某种方式,用户必须向您指示“请保存此数据”。它可以通过按钮、菜单选择、或离开活动(例如,onStop())或其他方式。我将其称为“触发器”。

在您的 EditText 场景中,当触发器发生时,您将对 SQLiteDatabase 执行 insert()update() 或其他操作 包含通过 getText() 检索的 EditText 内容。

在您的 RatingBar 场景中,当触发发生时,您将对 SQLiteDatabase 执行 insert()update() 或其他操作 与通过 getRating() 检索的 RatingBar 内容。

Let's assume that you have an app.

Let's further assume that you have a user.

Let's keep going out on this limb and assume that you have an an activity in the app, in which the user will fill in data, and that the objective is for this data to wind up in a SQLite database.

Somewhere, somehow, the user has to indicate to you "Please save this data". It could be via a button, or a menu choice, or leaving the activity (e.g., onStop()), or whatever. I will call this the "trigger".

In your EditText scenario, when the trigger occurs, you would do an insert() or update() or whatever to the SQLiteDatabase with the contents of the EditText, retrieved via getText().

In your RatingBar scenario, when the trigger occurs, you would do an insert() or update() or whatever to the SQLiteDatabase with the contents of the RatingBar, retrieved via getRating().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文