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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:17:26+00:00 2026-06-03T08:17:26+00:00

When trying you get the activity to change on the click of a button,

  • 0

When trying you get the activity to change on the click of a button, I found you had to use Intent. But when used in my code it does not seem to work. Are there any problems with the code I have?

  public class SearchActivity extends Activity implements OnClickListener{

    private ListView recipes;
    Intent intent;
    Button button;
    EditText input;

    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          setContentView(R.layout.searchlist);

          //EditText input = (EditText)findViewById(R.id.recipeName);
          button = (Button)findViewById(R.id.submit);
          input = (EditText)findViewById(R.id.recipeName);

          //recipes = (ListView)findViewById(R.id.recipes);
          //recipes.setAdapter(new ArrayAdapter<String> (this, R.layout.main, getResources().getStringArray(R.array.BaconSandwich)));
          button.setOnClickListener(this);
      }

      public void onClick(View clicked) {

          String value = input.getText().toString();
          Toast.makeText(this, value, Toast.LENGTH_SHORT).show();

          if(clicked == button) {
            recipes = (ListView)findViewById(R.id.recipes);
            Toast.makeText(this, "It is working for this item.", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(SearchActivity.this, RecipeMethodActivity.class);
            SearchActivity.this.startActivity(i);
          }
      }

Im not sure if it is just a simple naming error, or the way I am calling it is wrong. Any help would be great.

Also I have added the activity I want to change to (RecipeMethodActivity) into the Android Manifest.

  • 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-03T08:17:27+00:00Added an answer on June 3, 2026 at 8:17 am

    You need to check for the view’s Id in your onClick method, like this:

    public void onClick(View clicked) {
    
          String value = input.getText().toString();
          Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
    
          if(clicked.getId() == R.id.submit) {
            recipes = (ListView)findViewById(R.id.recipes);
            Toast.makeText(this, "It is working for this item.", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(SearchActivity.this, RecipeMethodActivity.class);
            SearchActivity.this.startActivity(i);
          }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the entered data from an activity. From my main
I'm trying to get a Spinner View from an added Fragment to my activity
OK, trying to get images from my SD card to show in an activity
I am trying to create a searchable activity however when I get to this
I'm trying to get a couple spinners to change dynamically based on their previous
Im trying to change this code to do reverse geocoding as well. Coordinates work
Hai am trying to get the gps location using BroadCast Receiver.its working fine,But i
I'm still learning Java. I'm trying to get use SharedPreferences to set the url
Im trying to change the label of an android activity: <activity android:name=.MainActivity android:label=@string/title_activity_main> The
I'm trying to change the item colors of a listview in android, but I

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.