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

The Archive Base Latest Questions

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

I am trying to create a custom ListView using an ArrayAdapter . POJO Item

  • 0

I am trying to create a custom ListView using an ArrayAdapter. POJO Item class:

public class Item {

    String itemTitle = "", itemTimestamp = "", itemDescription = "";
    ImageView itemImage;

    public String getTitle() {
        return itemTitle;
    }

    public String getDescription() {
        return itemDescription;
    }

    public String getTimeStamp() {
        return itemTimestamp;
    }

    public ImageView getImage() {
        return itemImage;
    }

    public Item(String itemTitle, String itemTimestamp, String itemDescription,
            ImageView itemImage) {
        super();
        this.itemTitle = itemTitle;
        this.itemDescription = itemDescription;
        this.itemTimestamp = itemTimestamp;
        this.itemImage = itemImage;
    }

    public void setItemTitle(String title) {
        itemTitle = title;
    }

    public void setItemTimestamp(String timestamp) {
        itemTimestamp = timestamp;
    }

    public void setItemDescription(String itemDesc) {
        itemDescription = itemDesc;
    }

    public void setItemImage(ImageView image) {
        itemImage = image;
    }

}

And here how the custom array adapter looks like.It is shown as below:

public class ListAdapter extends ArrayAdapter<Item> {

    public ListAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        // TODO Auto-generated constructor stub
    }

    private List<Item> items;

    public ListAdapter(Context context, int resource, List<Item> items) {
        super(context, resource, items);
        this.items = items;
}

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

    if (v == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(R.layout.list_item_default, null);
    }

    Item p = items.get(position);

    if (p != null) {

        TextView list_title = (TextView) v.findViewById(R.id.list_title);
        TextView list_description = (TextView) v.findViewById(R.id.list_description);
        TextView list_timestamp = (TextView) v
                .findViewById(R.id.list_timestamp);
        ImageView list_image = (ImageView) v.findViewById(R.id.list_image);

        if (list_title != null) {
            list_title.setText(p.getTitle());
        }

        if (list_description != null) {
            list_description.setText(p.getDescription());
        }

        if (list_timestamp != null) {
            list_timestamp.setText(p.getTimeStamp());
        }

        if (list_image != null) {
            list_image.setImageResource(p.getImage(R.drawable.btn_bg_pressed));
        }
    }

    return v;
}

}

Error:

The method setImageResource(int) in the type ImageView is not applicable for the arguments (ImageView)

I am not sure how to set the default image for the ListView and that should change according the the array I feed it in at run time from the internet.

  • 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-26T21:58:52+00:00Added an answer on May 26, 2026 at 9:58 pm

    You are trying to assign as an image(picture) a ImageView object.
    In your Item class instead of an ImageView you could store the id(like R.drawable.some_name) of the image for that particular item object as an int(like R.drawable.btn_bg_pressed) and then in your getView() method the assignment will be :

    list_image.setImageResource(p.getImageId())
    

    where the method getImageId()(from class Item) would be like this:

    private int itemImageId;
    
    public int getImageId() {
       return itemImageId;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom class that is based off of an XML
I am trying to create a custom scrollbar and am using images as button.
I'm trying to create custom listview in android. When I try to access my
I'm trying to create a custom search interface for Apache Solr using Drupal ,
I'm trying to create a custom timestamp field. class TimestampKey(models.CharField): __metaclass__ = models.SubfieldBase def
What I've done Hello Guys, I'm trying to create a custom ListView layout. I've
I'm trying to create a custom view (one that is not 100% listview, for
I'm trying to create a custom ListView layout similar to android.R.layout.simple_list_item_2. However, when I
Im trying to create a custom version of the RequiredAttribute to replace the built
I'm trying to create a custom JSP tag that would take an array object

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.