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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:44:16+00:00 2026-05-28T15:44:16+00:00

I have been following this tutorial and everything was going nice and easy until

  • 0

I have been following this tutorial and everything was going nice and easy until I decided to implement some stuff on my own.
I have the following adapter:

package alphabet.fast.scroll;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

public class interactiveArrayAdapter extends ArrayAdapter<model> {

    private final List<model> list;
    private final Activity context;

    public interactiveArrayAdapter(Activity context, List<model> list) {
        super(context, R.layout.custom_row, list);
        this.context = context;
        this.list = list;
    }

    static class ViewHolder {
        protected ImageView avatar;
        protected TextView name;
        protected CheckBox checkbox;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.custom_row, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder.avatar = (ImageView) view.findViewById(R.id.avatar);
            viewHolder.name = (TextView) view.findViewById(R.id.name);
            viewHolder.checkbox = (CheckBox) view.findViewById(R.id.checkBox);
            viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    model element = (model) viewHolder.checkbox.getTag();
                    element.setSelected(buttonView.isChecked());
                }
            });
            view.setTag(viewHolder);
            viewHolder.checkbox.setTag(list.get(position));
        } else {
            view = convertView;
            ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.avatar.setImageResource(R.drawable.icon2);
        holder.name.setText(list.get(position).getName());
        holder.checkbox.setChecked(list.get(position).isSelected());
        return view;
    }
}

this model:

package alphabet.fast.scroll;

import android.graphics.drawable.Drawable;

public class model {

    private Drawable avatar;
    private String name;
    private boolean selected;

    public model(String name) {
        this.name = name;
        selected = false;
    }

    public model(String name, Drawable avatar) {
        this.avatar = avatar; 
        this.name = name;
        selected = false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
}

and MainActivity :

package alphabet.fast.scroll;

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

import android.app.ListActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class tutorial extends ListActivity {

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        ArrayAdapter<model> adapter = new interactiveArrayAdapter(this, getModel());
        setListAdapter(adapter);
    }

        private List<model> getModel() {
            List<model> list = new ArrayList<model>();
            list.add(get("Linux"));
            list.add(get("Windows7"));
            list.add(get("Android"));
            list.add(get("iPhone"));
            list.add(get2("Problem coming up here", getResources().getDrawable(R.drawable.icon)));
            return list;
        }

        private model get(String s) {
            return new model(s);
        }

        private model get2(String s, Drawable av) {
            return new model(s, av);
        }
}

Can you please tell me what is wrong with my code and why my constructor with text and drawable is not working properly – I don’t get an updated avatar for the Problem coming up here row in the ListView ?

  • 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-28T15:44:17+00:00Added an answer on May 28, 2026 at 3:44 pm

    instead of updateing the imageView with the avatar image you are doing
    holder.avatar.setImageResource(R.drawable.icon2);

    Rather you should make a method in the Avatar class like
    public Drwable getAvatarImage(){
    return this.avatar;
    }

    Then you should do as below in your getView method:
    holder.avatar.setImageResource(list.get(position).getAvatarImage);

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

Sidebar

Related Questions

I've been following alone with this tutorial . Everything is going great, until I
I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I have been following this tutorial series for OpenGL : GLUT : http://www.lighthouse3d.com/opengl/glut/ I
I am using Rails 3.1 and have been using this railscast tutorial to implement
i have been following this tutorial for the pagerAdapter. http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/ My problem is that
I've been following this tutorial on how to implement a Silverlight application. The tutorial
I am new to WP7 programming and I have been following this tutorial http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx
I have been following this tutorial. I'm having conceptual trouble at the point where
I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I've been following this tutorial to create my own custom project type and for

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.