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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:07:38+00:00 2026-05-27T10:07:38+00:00

I’ve been working on an app that displays feeds in a list activity. At

  • 0

I’ve been working on an app that displays feeds in a list activity.
At first, I’m getting the information and parsing it, and I put it in a array of “FeedType” that I’ve created, that has 3 fields: Bitmap pic, String name and View content.
The content represent the feed’s content, and there’s different type of contents.
This array is being initialized in the parsing process.

I created the feed layout in a xml file.
Created a ImageView, TextView and LinearLayout that will contain the “content” by using addView().
I’ve created a wrapper and create my ListAdapter to reuse the object in the list.

My problem start when I’m trying to use add a view who is already a child of other LinearLayout, and it’s happening because when I retrieve the content from the array I’m retireving the reference to the existing view, and not a new view.

Is there a way to create a new view from existing view? Or somebody got other solution?

Code:

public class FeedType {

    private Bitmap profilePicSrc;
    private String name;
    private View feedContent;
    private Context context;
    private final String PIC_BASE_SRC = "xxx";
    private final String PIC_END_SRC = "xxx";


    public FeedType(String contactId, String name, View feedContent, Context context){
        try {
            this.profilePicSrc = BitmapFactory.decodeStream((InputStream)new URL(PIC_BASE_SRC + contactId.toString() + PIC_END_SRC).getContent());
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.name = name;
        this.context = context;
        this.feedContent = feedContent;
    }

    public String getName(){
        return name;
    }

    public Bitmap getProfilePicture(){
        return profilePicSrc;
    }

    public View getContent(){
        return this.feedContent;
    }
}

Wrapper class:

public class FeedWrapper {

    private View base;
    private ImageView pic = null;
    private TextView name = null;
    private LinearLayout content = null;

    public FeedWrapper(View base) {
        this.base = base;
    }

    public ImageView getProfilePicture() {
        if (pic == null) {
            pic = (ImageView)base.findViewById(R.id.pic);
        }
        return(pic);
    }

    public TextView getName() {
        if (name == null) {
            name = (TextView)base.findViewById(R.id.name);
        }
        return(name);
    }

    public LinearLayout getContent() {
        if (content == null) {
            content = (LinearLayout)base.findViewById(R.id.content);
        }
        else content.removeAllViews();
        return(content);
    }

}

ListAdapter class:

private class FeedListAdapter extends ArrayAdapter<Object> {

        public FeedListAdapter() {
            super(Feeds.this, R.layout.feed, new Object[feedArrLength]);
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            View feed = convertView;
            FeedWrapper wrapper = null;

            if (feed == null) {

                feed = getLayoutInflater().inflate(R.layout.feed, parent, false);
                wrapper = new FeedWrapper(feed);
                feed.setTag(wrapper);
            }
            else {
                wrapper = (FeedWrapper)feed.getTag();
            }

            wrapper.getName().setText(arr.get(position).getName());
            wrapper.getProfilePicture().setImageBitmap(arr.get(position).getProfilePicture());
            wrapper.getContent().addView(arr.get(position).getContent());
            return(feed);
        }
    }

I know that’s a bit difficult to understand, if you have questions please ask.

Thanks in advance, Elad!

  • 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-27T10:07:39+00:00Added an answer on May 27, 2026 at 10:07 am

    I think it’s a wrong way to keep View in FeedType object. Keep only data in FeedType.

    For example create new class FeedContent which contains parsed data about feed content (not any views):

    class FeedContent {
    
    ... // i.e. private List<String> contents;
    
    }
    

    Then change your FeedType class:

    public class FeedType {
    
    private Bitmap profilePicSrc;
    private String name;
    private FeedContent feedContent;
    private Context context;
    private final String PIC_BASE_SRC = "xxx";
    private final String PIC_END_SRC = "xxx";
    
    
    public FeedType(String contactId, String name, FeedContent feedContent, Context context){
        try {
            this.profilePicSrc = BitmapFactory.decodeStream((InputStream)new URL(PIC_BASE_SRC + contactId.toString() + PIC_END_SRC).getContent());
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.name = name;
        this.context = context;
        this.feedContent = feedContent;
    }
    
    public String getName(){
        return name;
    }
    
    public Bitmap getProfilePicture(){
        return profilePicSrc;
    }
    
    public FeedContent getContent(){
        return this.feedContent;
    }
    

    }

    And then make your FeedListAdapter like:

    private class FeedListAdapter extends ArrayAdapter<Object> {
    
        public FeedListAdapter() {
            super(Feeds.this, R.layout.feed, new Object[feedArrLength]);
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            View feed = convertView;
            FeedWrapper wrapper = null;
    
            if (feed == null) {
    
                feed = getLayoutInflater().inflate(R.layout.feed, parent, false);
                wrapper = new FeedWrapper(feed);
                feed.setTag(wrapper);
            }
            else {
                wrapper = (FeedWrapper)feed.getTag();
            }
    
            wrapper.getName().setText(arr.get(position).getName());
            wrapper.getProfilePicture().setImageBitmap(arr.get(position).getProfilePicture());
            View feedContentView = createContentView(arr.get(position).getContent());
            wrapper.getContent().addView(feedContentView);
            return(feed);
        }
    
        private View createContentView(FeedContent feedContent) {
            ... // Here you shuold inflate new view and fill it with data from "feedContent"
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into

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.