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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:50:22+00:00 2026-05-31T18:50:22+00:00

As a simplified example, consider a ListView that can contain both sub-categories and book

  • 0

As a simplified example, consider a ListView that can contain both sub-categories and book titles. If a book title is clicked, a new activity should start that shows the cover image. If a sub-category is clicked, a new list of books and categories is displayed.

A Row interface is defined as follows.

interface Row {
   void onClick();
   void draw(View v);
}

I would like to know how to prevent a dependency from the ListView‘s ArrayAdapter as well as from the implementer of onItemClickListener on the Row implementers (e.g.,Book and Category).

One of the forces driving this requirement is the “don’t repeat yourself” (DRY) principle: the ArrayAdapter implementation does not need to change when new row types are introduced.

  • 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-31T18:50:23+00:00Added an answer on May 31, 2026 at 6:50 pm

    Forgive my chicken-scratched “UML” below, but here’s how I do it.

    class ListAdapter extends ArrayAdapter<Row<?>> {
    ...
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = listViewRowViewRecycler.getView(convertView);
            rowProvider.get().getRow(position).draw(view);
            return view;
        }
    }
    

    The implementer of OnItemClickListener has a method like this:

    void onItemClick(AdapterView<?> adapterView, View view, int rowIndex, long rowId)
    {
       rowProvider.onItemClick(rowIndex);
    }
    

    Then RowProvider has a method like this:

    void onItemClick(int rowIndex) {
        rowList.get(rowIndex).onClick();
    }
    

    Then the Row interface has a method with signature void onClick() and there are Category and Book implementations of Row that provide the necessary behavior.

    UML Diagram

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

Sidebar

Related Questions

Let's consider following, simplified example: We have 2 tabs withing <rich:tabPanel switchType=ajax> , each
I've simplified this example as much as I can. I have a remote function:
consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String>
I have an app that's about presenting fictional simplified cities. Please consider the following
Consider the code below (which has been simplified). I have a service class that
This is a simplified example, to make sure that there are no asynchronous fading/animation
This is a simplified example that should be enough for the question. @interface MyClass:
Consider the following (simplified) example: abstract class Bar[T] { val f: PartialFunction[T, T] val
Consider this simplified example: #include <list> typedef std::list<int> IntList; class KindaIntList { public: IntList::const_iterator
Consider the following simplified example and desired output: class A { class combined_iterator {

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.