Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9105607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:08:53+00:00 2026-06-17T02:08:53+00:00

I have a problem with a listView that I made that has a ratingbar

  • 0

I have a problem with a listView that I made that has a ratingbar and a texview element.Its a very simple program that is meant to displays the list and stores the value of the stars that the user enters into the ratingBar. Unfortunately for some reason when I scroll up and down the rows that go out of the screen, when scrolled back in have their stars changed back to their intial value.The code is below. If anyone could help that would be great. Thanks.

package com.example.test;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;

public class MainActivity extends Activity implements RatingBar.OnRatingBarChangeListener {

private String[] textList = {"Pikachu","Raichu","Raticate","Ratata","Absol","Abra","Kadabra","Pidgey","Mime","Meowth","Mew","Squirtle","Blastoise","Goop","Kilobyte","Armada"};
private ArrayList<String> list = new ArrayList<String>();
ListView listView;

protected void onCreate(Bundle icicle) 
{
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);

    for(int i=0; i<textList.length; i++)
    {
        list.add(i,textList[i]);
    }

    listView = (ListView)findViewById(R.id.listRow);
    listView.setAdapter(new setListView(list));
}

class setListView extends ArrayAdapter<String>
{
    public setListView(ArrayList<String> list)
    {
        super(MainActivity.this, R.layout.custom_layout, R.id.text, list);
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;

        if(convertView == null)
        {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.custom_layout, parent, false);
        }

        RatingBar ratingBar = (RatingBar)row.findViewById(R.id.rating);
        RatingBarInfo rating;
        rating = (RatingBarInfo)ratingBar.getTag();
        if(rating == null)
        {
            rating = new RatingBarInfo(position);
            ratingBar.setTag(rating);
        }
        ratingBar.setRating(rating.getRating());

        TextView text = (TextView)row.findViewById(R.id.text);
        text.setText(list.get(position));

        return(row);
    }
}

class RatingBarInfo
{
    float rating;
    int position;

    public RatingBarInfo(int positionTemp)
    {
        rating = 2.0f;
        position = positionTemp;
    }

    public void setRating(float ratingTemp)
    {
        rating = ratingTemp;
    }

    public float getRating()
    {
        return rating;
    }

    public int getPosition()
    {
        return position;
    }
}

public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) 
{
    RatingBarInfo ratingChange = (RatingBarInfo)ratingBar.getTag();
    ratingChange.setRating(rating);
    ratingBar.setTag(ratingChange);
    ((ArrayAdapter<String>)listView.getAdapter()).notifyDataSetChanged();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:08:54+00:00Added an answer on June 17, 2026 at 2:08 am

    You forgot to set OnRatingBarChangeListener on your RatingBar.
    Just add this line into your getView() method and it should works well.

    ratingBar.setOnRatingBarChangeListener(MainActivity.this)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a problem in my program that has me somewhat stumped. I
I have made a ListView in my android application. But the problem is that
I have an activity which consists of a ListView . The problem is that
In one of my Activities I have a ListView that displays a list of
I have a listview that has a photograph from the gallery for each entry
I have a problem with ListView. the thing is that when I click on
I have a ListView In My Winform that has 4columns, Name, Money, ID and
I have some problem to use listview and SherlockActivity. my problem is that I
I have a listview which I populate from a webservice query. Problem is that
I have a problem with a listview that crashes during orientation change. More specifically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.