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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:50:10+00:00 2026-05-19T10:50:10+00:00

I’m not sure if this is just something that is up to developer opinion

  • 0

I’m not sure if this is just something that is up to developer opinion but I am creating an android app and have a Listview that displays a custom view. My layout basically consists of a View (as an xml resource file and a class that derives from the view that is the root), a Domain Model object (has the data to be bound to the view) and an adapter which derives from BaseAdapter that binds the data from the Domain Model to the View in the getViewMethod as follows:

Model: SampleItem
Custom View: SampleView
Adapter: (code below)

   public View getView(int position, View convertView, ViewGroup parent) {
  SampleView sampleView;

  SampleItem item = (SampleItem)getItem(position);

  if(convertView == null) {
   sampleView = new SampleView(_context);
  }
  else {
   sampleView = (SampleView)convertView;
  }

  sampleView.setTitle(item.getTitle());
  sampleView.setContentText(item.getContent());
  sampleView.setItemRowNumer(item.getRowNumber());
  ... //etc
  return sampleView;
}

This is how I’ve always seen it done, but I wonder is this the right way to do it.

My thought, coming from a different approach to data binding, is that the actual view class doesn’t have a concept of what it’s model is, and diverting the control to how data is bound to it to an adapter class that may not exist if moved elsewhere.

I was thinking that the custom view class has a reference to the object that is bound to it and in it’s constructor it populates the view based on the data. So the adapter is essentially a shell class that only does this:

   public View getView(int position, View convertView, ViewGroup parent) {
  SampleView sampleView;

  SampleItem item = (SampleItem)getItem(position);

  if(convertView == null) {
   sampleView = new SampleView(_context, item);
  }
  else {
   sampleView = (SampleView)convertView;
  }

  return sampleView;
 }

And the actual constructor for the view would know its model and populate itself as opposed to the Adapter doing work that seems outside of it’s responsibility.

  • 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-19T10:50:11+00:00Added an answer on May 19, 2026 at 10:50 am

    The adapter should do it. Two reasons.

    1) CursorAdapter#bindView: it’s defined in the framework. It’s idiomatic and it will be what other android programmers would expect to see while reading your code. IMHO keeping things idiomatic improves code maintenance and legibility.

    2) The way AdapterView classes work in android is that they reuse the Views returned from the adapter. This is so that a lot of new objects aren’t created during scroll/flick/etc. animations and UI events. In order for that to work the AdapterView passes that View back to the adapter and expects that view to be reused. IMHO the intention and expectation is for the Adapter to handle updating and rebinding that View. If you attempt your method and keep the binding in the Views constructor then the only time data binding would happen would be in the constructor. You would then need to move that binding into a separate function possibly cluttering the class interface and with inheritance getting into other problems.

    For me, I prefer that a View only care about how to display something. That’s all the responsibilities I really want it to worry about. I think that’s enough since some views can become quite complex. I like to leave it to other classes to worry about telling the View what it should be displaying and where that data should be coming from. Sometimes this means very simple bindings, i.e., calling toString() multiple times in a row. However, it decouples the data that is being displayed from the underling data which allows for one to change with the possibility of reusing the other.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text

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.