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 8039373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:32:56+00:00 2026-06-05T03:32:56+00:00

i am use this for setting checkbox in listview i have follow all step

  • 0

i am use this for setting checkbox in listview i have follow all step as per given tutorial, but there are some critical issue with output, is that when i am select first checkbox and scroll down it will change selected item and automatically appear 3rd.

so i think there are something wrong with getview. so please help me out this ….

here is my code ::

package com.AppFavorits;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.ListActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.RatingBar;

public class Favorites extends ListActivity {
    protected static final String TAG = "Favorites";
    CommentsDataSource datasource;
    ListView lstFavrowlistv;
    ArrayList alAppName;
    float[] rate;
    boolean[] bSelected;
    ArrayList<Comment> alPackagenm;
    Drawable[] alIcon;
    ViewHolder holder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        datasource = new CommentsDataSource(this);
        datasource.open();

        alAppName = datasource.getAllComments();
        alPackagenm = datasource.getAllPackage();

        Log.i(TAG, "values >>>" + alAppName);
        Log.i(TAG, "values >>>" + alPackagenm);
        int inc = 0;
        alIcon = new Drawable[200];
        for (int i = 0; i < alPackagenm.size(); i++) {
            Log.i(TAG, "Appname >>>" + GetAllApp.lstpinfo.get(i).pname);
            for (int j = 0; j < GetAllApp.lstpinfo.size(); j++) {
                if (alPackagenm
                        .get(i)
                        .toString()
                        .equalsIgnoreCase(
                                GetAllApp.lstpinfo.get(j).pname.toString())) {
                    alIcon[inc] = GetAllApp.lstpinfo.get(j).icon;
                    Log.i("TAG", "sqlPackagename"
                            + alPackagenm.get(i).toString());
                    Log.i("TAG", "from getAllapp"
                            + GetAllApp.lstpinfo.get(j).pname.toString());
                    inc++;
                }

            }
        }

        ArrayList<RowModel> list = new ArrayList<RowModel>();
        ArrayList<Model> Mlist = new ArrayList<Model>();
        rate = new float[alAppName.size()];
        bSelected = new boolean[alAppName.size()];
        Iterator itr = alAppName.iterator();
        String strVal = null;
        while (itr.hasNext()) {
            strVal += itr.next().toString() + ",";

        }

        int lastIndex = strVal.lastIndexOf(",");
        strVal = strVal.substring(0, lastIndex);
        System.out.println("Output String is : " + strVal);
        String strAr[] = strVal.split(",");

        for (int i = 0; i < strAr.length; i++) {
            System.out.println("strAr[" + i + "] " + strAr[i]);
        }

        for (String s : strAr) {
            list.add(new RowModel(s));
        }
        for (String s : strAr) {
            Mlist.add(new Model(s));
        }
        setListAdapter(new RatingAdapter(list, Mlist));
        datasource.close();
    }

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

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

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

            return (label);
        }
    }

    private RowModel getModel(int position) {
        return (((RatingAdapter) getListAdapter()).getItem(position));

    }

    class RatingAdapter extends ArrayAdapter<RowModel> {
        private ArrayList<Model> mlist;

        RatingAdapter(ArrayList<RowModel> list, ArrayList<Model> mlist) {
            super(Favorites.this, R.layout.outbox_list_item,
                    R.id.txvxFavrowiconappname, list);
            this.mlist = mlist;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            View row = super.getView(position, convertView, parent);
            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;
                        rate[position] = rating;

                    }
                };
                holder.chkbxFavrowsel
                        .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                            @Override
                            public void onCheckedChanged(
                                    CompoundButton buttonView, boolean isChecked) {
                                Model element = (Model) holder.chkbxFavrowsel
                                        .getTag();
                                element.setSelected(buttonView.isChecked());
                                bSelected[position] = isChecked;

                            }
                        });
                holder.chkbxFavrowsel.setTag(mlist.get(position));
                holder.ratingBar1.setOnRatingBarChangeListener(l);
            } else {
                row = convertView;
                ((ViewHolder) row.getTag()).chkbxFavrowsel.setTag(mlist
                        .get(position));
            }

            RowModel model = getModel(position);
            ViewHolder holder = (ViewHolder) row.getTag();
            holder.ratingBar1.setTag(new Integer(position));
            holder.ratingBar1.setRating(model.rating);
            holder.imgvFavrowiconappicon.setImageDrawable(alIcon[position]);
            holder.txvxFavrowiconappname.setText(alAppName.get(position)
                    .toString());
            holder.chkbxFavrowsel.setChecked(mlist.get(position).isSelected());

            return (row);
        }
    }
}
  • 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-05T03:32:58+00:00Added an answer on June 5, 2026 at 3:32 am

    I really don’t understand your code exactly what you are trying to do. I haven’t seen before this you are checking holder == null where as it should be convertView == null. If you have a scrolling issue you can check my blog post

     holder = (ViewHolder) row.getTag();
                if (holder == null) {
                    holder = new ViewHolder(row);
                    row.setTag(holder);
                   ...
                }
               else {
                    row = convertView;
                    ((ViewHolder) row.getTag()).chkbxFavrowsel.setTag(mlist
                            .get(position));
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that looks like this: <ul class=toggleList> <li><input type=checkbox name=toggleCbx1 id=toggleCbx1
use this website a lot but first time posting. My program creates a number
i use this code for exporting gridview to Excel in asp.net - c# .....but
I have a strongly typed partial view CheckBox.ascx that renders a checkbox. This is
I'm trying to use a select all checkbox to select a column of checkboxes.
I have been searching round the internet for days on this matter but I
I have read lots of questions and answers about this issue on StackOverflow, but
I use this wonderful tool, tinyMCE, for editing pages at my website. But i
The situation is this: I have some JavaScript that creates an interactive dialogue (and
use this code, in the Preferences activity, to know when the reset preference has

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.