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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:31+00:00 2026-05-27T17:27:31+00:00

I am trying to setup an activity and when I try to assign some

  • 0

I am trying to setup an activity and when I try to assign some of my views to names in the .java file its telling that R.layout.bathing does not have field datePicker1 and it does have it. Here is my two code snippets. What should I change to get this to work?

bathing.java

setContentView(R.layout.bathing);
setTitle("Please Select Bathing Options");
bathdate = (DatePicker)findViewById(R.layout.bathing.datePicker1);
bathtime = (TimePicker)findViewById(R.layout.bathing.timePicker1);
add = (Button)findViewById(R.layout.bathing.button1);

bathing.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="@string/bath_tracking"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="16dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/datePicker1"
        android:layout_marginTop="51dp"
        android:text="@string/date"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/datePicker1"
        android:layout_below="@+id/datePicker1" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/timePicker1"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="50dp"
        android:text="@string/time"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/timePicker1"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Yes" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/radioGroup1"
        android:layout_below="@+id/radioGroup1"
        android:text="@string/No" />

    </RadioGroup>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/radioGroup1"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="36dp"
            android:text="@string/hair"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/timePicker1"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/radioGroup1"
            android:inputType="textMultiLine" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editText1"
            android:layout_centerHorizontal="true"
            android:text="@string/Add"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText1"
            android:layout_alignBottom="@+id/editText1"
            android:layout_alignParentLeft="true"
            android:text="@string/comment"
            android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>
  • 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-27T17:27:31+00:00Added an answer on May 27, 2026 at 5:27 pm

    You have to access view objects via their id, instead of

    bathdate = (DatePicker)findViewById(R.layout.bathing.datePicker1);
    

    use

    bathdate = (DatePicker)findViewById(R.id.datePicker1);
    

    and so on. IDs are global, they are not specific to a certain layout.

    That doesn’t neccessarily mean that each view has to have an unique name. The most important thing to know is that findViewById() only searches in the view hierachy of the current activity (you can try this by calling it before setContentView() – it will always return null). In the end it means that IDs should be unique in a single layout file.

    There is no problem in having the same id in multiple layouts. Often it’s even useful. Consider having an activity with a normal layout in res/layout/main.xml and a different layout for the landscape format in res/layout-land/main.xml. Android will manage these layouts for you. If you give views with identical purposes a different, unique id, you would have to do something along this in your code (pseudocode example):

    if(layout == portrait)
        view = findViewById(R.id.viewid_portrait);
    else if(layout == landscape)
        view = findViewById(R.id.viewid_landscape);
    

    If both have the same ID you won’t have a conflict, but can access both via a single line call of findViewById().

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

Sidebar

Related Questions

I am trying to setup an activity in Android that has 50% of the
Trying to setup an SSH server on Windows Server 2003. What are some good
After trying to setup my site for Google Webmaster Tools I found that my
I'm trying to create a setup activity for my Android application which my users
What I'm trying to achieve: Reduce memory usage of activity that is no longer
I'm trying setup a subset of boost and get it properly compiled using bjam,
Trying to setup a CodeIgniter based project for local development (LAMP stack), and once
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but
I'm trying to setup an Apache/PHP/Postgresql server locally on my machine. I'm using Windows
I am trying to setup tracd for the project I am currently working on.

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.