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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:27:34+00:00 2026-06-10T12:27:34+00:00

I have a class that is supposed to call another activity depending on which

  • 0

I have a class that is supposed to call another activity depending on which button has been clicked. This is done by checking the available IDs.

My problem is: The view that is passed to my class has no id, or rather, its value is NO_ID. What puzzles me is that the view, which is a button, does have an ID.

public class StrengthOrganizer extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_strength_organizer);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_strength_organizer, menu);
    return true;
}


public void notifyActivity(View view) {
    Intent intent = null;

    int id = view.getId();

    switch(id){
        case    R.id.button_log_book_launcher:
                intent = new Intent(this, LogBook.class);
                break;

        case    R.id.button_programming_launcher:
                intent = new Intent(this, Programming.class);
                break;

        case    R.id.button_visualizer_launcher:
                intent = new Intent(this, Visualizer.class);
                break;

        default:
                return;
    }

    startActivity(intent);
}
}

The corresponding XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button android:name="@+id/button_log_book_launcher"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:text="@string/button_log_book_launcher"
        android:onClick="notifyActivity" />

<Button android:name="@+id/button_programming_launcher"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:text="@string/button_programming_launcher"
        android:onClick="notifyActivity" />

<Button android:name="@+id/button_visualizer_launcher"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:text="@string/button_visualizer_launcher"
        android:onClick="notifyActivity" />

</LinearLayout>

Why does the view object have no ID if it’s been give in the XML file?

  • 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-06-10T12:27:35+00:00Added an answer on June 10, 2026 at 12:27 pm

    You used android:name instead of android:id in your XML to assign the ids. Use the latter instead.

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

Sidebar

Related Questions

I have a util class that is supposed to call a method on a
First suppose that I have an abstract class, let's call it AbstractClass. Suppose public
So I have a static class that is supposed to be used as a
Suppose that we have a class called class1. The class1 has a method called
I have a class IPAddressString that has: a private field of type String called
I have an instance of a NSObject class that is supposed to parse a
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
Suppose I have a class that processes some data: class SomeClass { public: void
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a Python class that I want to add an extra property

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.