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

  • Home
  • SEARCH
  • 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 529783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:07:40+00:00 2026-05-13T09:07:40+00:00

i wrote a View class based on ViewSwitcher and now I want to write

  • 0

i wrote a View class based on ViewSwitcher and now I want to write helper classes for the view like known form the ListView: ListAdapter, ListActivity and so on..

Regarding the activity class I ran into a problem. The ListActivity forces you to add a ListView to your activity with a fixed id: @id/android:list. In my base activity class i want to archive the same, forcing a special id so that my helper classes can access the view object.

As I’m writing a general lib that could be used in various projects I can’t use R.id.foobar to get the view as there’s no R class. The specific project will an own R.java.

So I peeked at the source code of ListActivity and found:

View emptyView = findViewById(com.android.internal.R.id.empty);
mList = (ListView)findViewById(com.android.internal.R.id.list);
if (mList == null) {
    throw new RuntimeException(
        "Your content must have a ListView whose id attribute is " +
        "'android.R.id.list'");
}

Ok, I could write my on R class, put it directly into my package and try to access it in the same way but I’ve no clue what value the id should have or need?

Also I couldn’t find any R class at android_frameworks_base/core/java/com/android/internal

And even if this problem is solved: How can the user of my lib access “my id” from his layout XML?

Thanks for your help! 🙂

  • 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-13T09:07:40+00:00Added an answer on May 13, 2026 at 9:07 am

    I do not think this is safe, as Android has not supplied reusable widget authors with an ID range to use for your desired purpose.

    Instead, do one of the following:

    1. Have the reuser of your widget pass in the appropriate ID.
    2. Use Resources#getIdentifier() to look up an ID in the R.* “namespace” given the string form of the name. If you go this route, be sure to cache this result, as it is a bit expensive to look up, apparently.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.