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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:08:43+00:00 2026-05-28T00:08:43+00:00

I have an APP, bundle ID is com.MYAPP, and then I create a new

  • 0

I have an APP, bundle ID is com.MYAPP, and then I create a new package named com.reference and inside that has ViewCache file. It first generated error on findViewById(R.id.text) and
findViewById(R.id.image) so, I had to import com.MYAPP.R to rid of the errors. But under the Layout folder I have many .xml layout files that could use the id of =R.id.text and R.id.image.
I thought I need to specifiy a specific xml to pointed to so ViewCache know exactly which xml it used. I thought I need to import com.MYAPP.R.row_item.xml.

I also has mainapp.xml that use id.text and id.view.image under the layout folder.
but it would NOT let me specify import com.MYAPP.R.row_item.xml.

So What should I specify on the import? I think import com.MYAPP.R is Not enough.

package com.reference;

import com.MYAPP.R;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class ViewCache {

private View baseView;
private TextView textView;
private ImageView imageView;

public ViewCache(View baseView) {
    this.baseView = baseView;
}

public TextView getTextView() {
    if (textView == null) {
        textView = (TextView) baseView.findViewById(R.id.text);
    }
    return textView;
}

public ImageView getImageView() {
    if (imageView == null) {
        imageView = (ImageView) baseView.findViewById(R.id.image);
    }
    return imageView;
}

}

  • 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-28T00:08:43+00:00Added an answer on May 28, 2026 at 12:08 am

    To clarify some naming: What you call bundle id (com.MYAPP) is your application package (which is defined in the manifest file).

    The R.java file contains all ids generated from your resources. It is located in <application-package>.R (so in your case com.MYAPP.R). If you define the same id in multiple layout file it will result in a single id within the R file.

    findViewById(id) looks in a view for a child view with the specified id. It does NOT look for a view with this id in all your layout files.

    If you do the following for example:

    public class MyActivity extends Activity {
     public void onCreate(Bundle b) {
       super.onCreate(b);
       this.setContentView(R.layout.myView); // you set the view here
       TextView tv = (TextView) findViewById(R.id.text); // this looks in the layout myView for an item with id text
     }
    }
    

    In your example findViewById(..) will look for a childview with id text within baseView. Only baseView will be searched for an element with id text, not any of the other layouts. So the result of findViewById(..) depends on what you assign to baseView.

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

Sidebar

Related Questions

I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
Have an app that has listings - think classified ads - and each listing
I have a settings bundle in my iPhone app, with the following PList: Type:
I have successfully created an app that reads from a bundled .plist file and
I have app in which i have recorded sound files i want that i
have an app that finds your GPS location successfully, but I need to be
in my app I have an overlay of pins that marks a point of
I have app.js and routes.js . In app.js I require routes.js . For routes.js
I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1). I
We have App A as main app. Now we build from it App B

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.