How to make a responsive RatingBar inside a sub-layout

432 Views Asked by At

The activity itself uses a table layout, in order to avoid the fill_parent width for the RatingBar (which messes up the number of starts) I placed a LinearLayout inside the TableLayout, and placed the ratingBar inside that. The alignment and all is fine now, however the RatingBar no longer responds to being pressed (I have an OnRatingBarChangeListener). It was working fine from outside the Linear Layout, is there something I have to adjust to get to the rating bar now?

Setting rating bar

ratingBar = (RatingBar) findViewById(R.id.ratingRatingBar);

Setting the Listener

ratingBar.setOnRatingBarChangeListener(changeRating);

The Listener itself (probably fine)

private OnRatingBarChangeListener changeRating = new OnRatingBarChangeListener()//function that updates the rating
    {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {
            // TODO Auto-generated method stub
            int currentRating = (int) ratingBar.getRating();//gets the rating on the bar
            dataSource.open();
            dataSource.updateRating((int) currentMovie.getId(), currentRating);//updates the entries rating with the new one
            dataSource.close();

        }

    };

And the xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal" >

    <TextView
        android:id="@+id/nameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/descTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <VideoView
        android:id="@+id/trailerVideoView"
        android:layout_width="match_parent"
        android:layout_height="200dp" />

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <Button
            android:id="@+id/reverseButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/ReverseString" />

        <Button
            android:id="@+id/pauseButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/pauseString" />

        <Button
            android:id="@+id/playButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/playString" />

    </TableRow>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <RatingBar
            android:id="@+id/ratingRatingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:numStars="5"
            android:stepSize="1" />

    </LinearLayout>

    <Button
        android:id="@+id/backToStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/GoBackString" />

    <Button
        android:id="@+id/deleteCurrentButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/deleteText" />

</TableLayout>
1

There are 1 best solutions below

0
On

I found my issue, a silly one

android:isIndicator="true"

prevents the user from interacting with it, just a setting I had on without realizing.