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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:08:30+00:00 2026-05-25T06:08:30+00:00

I want to implement a ‘favorite list’ and let’s assume that I have got

  • 0

I want to implement a ‘favorite list’ and let’s assume that I have got an empty layout. At onCreate() there is super.onCreate(savedInstanceState); setContentView(R.layout.main); and then I open a database with my favorite animals, load a few things and add dynamically buttons to the layout.

The database schema is this:

CREATE TABLE animals(_id INTEGER PRIMARY KEY, name TEXT NOT NULL, layout TEXT NOT NULL)

and in the database there is:

_id - - - - - - - - name - - - - - - - - - layout
1 - - - - - - - - -- cat - - - - - - - - -- R.layout.cat
2 - - - - - - - - -- dog - - - - - - - - -- R.layout.dog
3 - - - - - - - - -- turtle - - - - - - - - R.layout.turtle

Of course the layouts/xml-files (R.layout.cat, R.layout.dog, R.layout.turtle) exist.

So then you see three buttons saying cat, dog and turtle. In the OnClickListener there is the following:

    Intent intent = new Intent(MyFavorites.this, Animal.class);  
    Log.d ("onClick", button.getmyLayout());  
    // Shows either R.layout.cat, R.layout.dog or R.layout.turtle 
    // depending on what button was pressed. This works fine.
    intent.putExtra("myLayout", button.getmyLayout());    
    // closes the database
    myDbHelper.close();
    startActivity(intent);

The Animal.classcan show all animal-xml-files because they all have the same functionality. This is why the layout is always passed on to the same class!

The Animal.class:

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final int myLayout = getIntent().getIntExtra("myLayout", R.layout.main);
            setContentView(myLayout);
        }

Now here is the problem. I pass on a String and not an Integer and in the log cat there is:

Key myLayout expected Integer but value was a java.lang.String. The default value 2130903044 was returned.

The default value is R.layout.main which you find in the autogenerated R.class as a hex number and in decimal it is 2130903044. So I do understand the error message. But I cannot think of another way to solve this problem. I was thinking about getters and setters in the R.class but of course they will be deleted at the next build.

  • 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-25T06:08:30+00:00Added an answer on May 25, 2026 at 6:08 am

    Please see this question, I think it is what you need. Basically you can get the resource by using a string …

    int i = this.getResources().getIdentifier("cat", "layout", this.getPackageName());
    

    And here is the documentation for getIdentifier().

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

Sidebar

Related Questions

i starter in jqgrid, i want implement inline edit in jqgrid i have this
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement a list of ViewPagers. Every item of a ListView is
i have question for example i want to implement binary tree with array i
I want implement a program that can do a a Vision-based Page Segmentation. I
I wrote small service class and I want implement something like that : service
everyone! My english is poor and sorry fot that. I want implement a function
I want to implement basic shopping cart functionality in my Rails app....are there any
I want to implement UITableView Where I want to have 3 buttons in each
I have WSDL and XSD files and want implement a webservice based on this

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.