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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:56:52+00:00 2026-06-02T16:56:52+00:00

I need to subclass TextView to have it hold some additional data for me.

  • 0

I need to subclass TextView to have it hold some additional data for me. I’m placing these new View objects into a ListView using a custom ListAdapter.

I have an action I want to perform onClick(), and it is the same action for all elements of the ListView, based on the additional data.

Would this definition, have any downsides or cause any problems?

public class UserTextView extends TextView implements OnClickListener {

    public int userId;

    public UserTextView(Context context) {
        super(context);

        this.setClickable(true);
        this.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

}

I would expect that the code in my onClick() implementation wouldn’t actually be copied, but would only exist once in memory and be called with the specific UserTextView‘s data. So I don’t expect extra memory usage. And in fact, not having an extra Class and Object (anonymous or not) might improve performance (though not in a real, meaningful way).

If needed, the setOnClickListener() method could be invoked to change the Listener if I needed different behavior for a specific object.

It just seems to fit well into what I need:

  1. A TextView that can hold extra data (userId)
  2. A TextView class that will have the same default behavior
  3. Can be created and managed easily by a ListAdapter

I just feel that I have never seen this done this way, and am suspicious that there is something I’m missing.

  • 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-06-02T16:56:54+00:00Added an answer on June 2, 2026 at 4:56 pm

    As far as I know everything not static is within memory once for each instance of a class. This means that by this design your code is nice and clean but looking and memory usage it does not make a difference.

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

Sidebar

Related Questions

In my application I need to view some data which are accessible with Intent.ACTION_VIEW
I have a UIImageView subclass and I need to have a pan gesture so
I have a subclass of UIImageView that I need to know when is touched.
In a UITableViewController subclass, there are some methods that need to be implemented in
Need to insert selected text on the page into textarea. There must be some
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I have a UIScrollView that I need to subclass and within the subclass I
These questions are purely asked out of curiosity. I don't actually need to subclass
I have a custom cell (subclass of UITableViewCell) with a textView inside of it.
I have a subclass of the ' str ' object and I need to

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.