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

  • Home
  • SEARCH
  • 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 7695013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:26:58+00:00 2026-05-31T21:26:58+00:00

I am trying to create an interactive ListView without extending the ListActivity class.The layout

  • 0

I am trying to create an interactive ListView without extending the ListActivity class.The layout should be a RatingBar to the left and a label to the right. This is the code I have so far, which does not have any compile errors, but crashes on startup of the app:

public class ProDroid_BAActivity extends Activity {
    private static final String[] items = { "lorem", "ipsum", "dolor", "sit",
        "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel",
        "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam", "vel",
        "erat", "placerat", "ante", "porttitor", "sodales", "pellentesque",
        "augue", "purus" };

ListView listv = (ListView) findViewById(R.id.listView1);
ArrayAdapter<RowModel> adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ArrayList<RowModel> list = new ArrayList<RowModel>();
    for (String s : items) {
        list.add(new RowModel(s));
    }

    adapter = new RatingAdapter(list);
    listv.setAdapter(adapter);

}

private RowModel getModel(int position) {
    return adapter.getItem(position);
}

class RatingAdapter extends ArrayAdapter<RowModel> {

    public RatingAdapter(ArrayList<RowModel> list) {
        super(ProDroid_BAActivity.this, R.layout.row, R.id.label, list);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = super.getView(position, convertView, parent);

        ViewHolder holder = (ViewHolder) row.getTag();
        if (holder == null) {
            holder = new ViewHolder(row);
            row.setTag(holder);

            RatingBar.OnRatingBarChangeListener l = new RatingBar.OnRatingBarChangeListener() {
                public void onRatingChanged(RatingBar ratingBar,
                        float rating, boolean fromTouch) {
                    Integer myPosition = (Integer) ratingBar.getTag();
                    RowModel model = getModel(myPosition);

                    model.rating = rating;

                    LinearLayout parent = (LinearLayout) ratingBar
                            .getParent();
                    TextView label = (TextView) parent
                            .findViewById(R.id.label);

                    label.setText(model.toString());
                }
            };

            holder.rate.setOnRatingBarChangeListener(l);



        }

        RowModel model = getModel(position);

        holder.rate.setTag(new Integer(position));
        // holder.text.setTag(new Integer(position));
        holder.rate.setRating(model.rating);
        // holder.text.setText(model.label);

        return row;
    }

}

class RowModel {
    String label;
    float rating = 2.0f;

    RowModel(String label) {
        this.label = label;
    }

    public String toString() {
        if (rating >= 3.0) {
            return (label.toUpperCase());
        }

        return (label);
    }
}
 }
  • 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-05-31T21:26:59+00:00Added an answer on May 31, 2026 at 9:26 pm

    Move the line:

    ListView listv = (ListView) findViewById(R.id.listView1);
    

    in the onCreate() method after you set the content view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a postgresql user and I'm trying to follow this : http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html CREATE TRIGGER
Trying to create a background-image slideshow and am getting this error... This is the
Im trying to create an interactive skeleton (human type) whereby when a user rolls
I'm trying to use Groovy to create an interactive scripting / macro mode for
I am trying to create an interactive book using corona and kwik (http://kwiksher.com).. i
I trying to create an application using vb 2010.This application handles booking of airline
I'm trying to create an interactive 3d representation of cells that are defined by
I am trying to create an interactive command line program and it seems that
I'm trying to create an interactive form. Your selections determine the next questions that
I'm trying to create a simple interactive image map where the user would be

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.