bty99
bty99

Reputation: 11

Users average reviews

I need my ratings bar to keep up with the user average rating. I have a main menu with several items which each have their own screen and description. I'm adding a rating bar to each screen so users can submit their product rating/see the average rating by others/see the number of ratings. Kind of like the customer reviews on the amazon app but without the bar graph. I have the xml file set up but need help with the java. Any help would be appreciated. Here is an example of just one of the screens.

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="40dp"
    android:text="TextView"
    android:textSize="50dp" />

<TextView
    android:id="@+id/tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="TextView" />

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="40dp"
    android:layout_weight="50" />


<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="150dp"
    android:text="Submit" />

</LinearLayout>

java

public class MainActivity extends Activity {

RatingBar ratings;
TextView tv1, tv2;
Button b; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RatingBar rb = (RatingBar) findViewById(R.id.ratingbar);

}
}

Upvotes: 0

Views: 427

Answers (1)

Pavlos
Pavlos

Reputation: 2181

In order to achieve something like that you will have to create an SQLiteDatabase on your app.

  1. Store the ratingBar values for every product a user rates, inside your Database.
  2. Post the values from your local SQLiteDatabase to a server.
  3. Edit the values that you get in the server. Find max-min-middle etc. and store them on a "global" Database.
  4. Post back to your Application the edited results.
  5. Repeat the above steps on your own timeshift and you will have the desired result!

Upvotes: 1

Related Questions