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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:25:10+00:00 2026-05-28T05:25:10+00:00

an abstract in my mind is something like idontknow x = (idontknow) findViewById(R.string.stringname); so

  • 0

an abstract in my mind is something like

idontknow x = (idontknow) findViewById(R.string.stringname);

so that whenever i change x the R.string.stringname would also change

and thus i can use the R.string.stringname anywhere in the same project

but obviously it is an error

edit:
i would like to input my name(R.string.name or global) and age(R.string.age or global) on an EditText field on a formActivity

and in another differentActivity i would like to have this:

TextView x = (TextView) findViewById(<some id>);
x.setText("Hello "+ getString(R.string.nfoname)+ "you are"+getString(R.string.nfoname)+"years old");
  • 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-28T05:25:11+00:00Added an answer on May 28, 2026 at 5:25 am

    This really seems like poor design. What are you doing that you don’t know the type of x, and it’s something that you need to persist across your application?

    Everything that gets returned by findViewById() is a View object or one of its subclasses. So, right off the bat you know you have a view object. Another thing is that findViewById doesn’t accept a String as a parameter, it only accept an int value, such that R.id.myVar is actually an integer corresponding to a View in the inflated hierarchy.

    If you absolutely have to do something like that, why wouldn’t you just use a common id value so that you’re always searching for the same id and assign it to a generic View object that can be compared using instanceof later? Like this:

    View view = findViewById(R.id.generic_id);
    if(view instanceof TextView) {TextView actualView=(TextView)findViewById(R.id.generic_id);}
    else {ImageView actualView = (ImageView)findViewById(R.id.generic_id);}
    return actualView;
    

    In that case, your ID could be a constant that couldn’t be changed, and you always can figure out what subclass of View you’re dealing with. This feels like a more maintainable design than having global variables floating around, in my opinion

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

Sidebar

Related Questions

Abstract: Can you propose a mathematical-ish algorithm over a plane of pixels that will
How would you refactor this, keeping in mind that you have dozens more of
Having in mind the abstract factory pattern, imagine that you have a class hierarchy
An abstract class can only be used as a base class which is extended
public abstract class MyAbs implements Comparable<MyAbs> This would work but then I would be
I would like to parse a self-designed file format with a FSM-like parser in
Is the following ok? (keep in mind that I didn't write the bodies of
Note: WinForms C# Early Learning Level! I would like some assistance with the best
Interface methods in C# can be implemented explicitly, so that their implementation is invoked
How can I have a generic abstract class, let's say Animal, and have it

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.