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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:35:57+00:00 2026-05-22T16:35:57+00:00

Thanks for taking the time to look into my problem with me. I’m very

  • 0

Thanks for taking the time to look into my problem with me. I’m very new to Android Development and this is my first application attempt. Any and all help would be appreciated. All advice is needed advice at this point.

Main issue at hand is the btnBack and btnSubmit are not triggering an onClick event. Please advise.

helloformstuff.java

package com.uDrew.helloformstuff;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
public class helloformstuff extends Activity implements OnClickListener {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.i("DrewDebug", "Loading: layout.main");

    setContentView(R.layout.main);

    Log.i("DrewDebug", "Loaded: layout.main");

    Log.i("DrewDebug", "Loading: Drunk Spinner");

    //Drunk Spinner
    Spinner spLevel = (Spinner) findViewById(R.id.spLevel);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.drunk_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spLevel.setAdapter(adapter);

    Log.i("DrewDebug", "Loaded: Drunk Spinner");

    Log.i("DrewDebug", "Listening for Buttons");
    //Listen for button clicks
    Button btnNext = (Button) this.findViewById(R.id.btnNext);
    Button btnSubmit = (Button) this.findViewById(R.id.btnSubmit);
    Button btnBack = (Button) this.findViewById(R.id.btnBack);

    if (btnNext!= null) {
        //If btnNext was hit
        btnNext.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

            Log.i("DrewDebug", "Button Hit: Next");
            //Log the beginning of this code 
            Log.i("DrewDebug", "BEGIN Next Code");

            //Change to second Screen
            setContentView(R.layout.second);

            //Initialize State Spinner
            Spinner spState = (Spinner) findViewById(R.id.spState);
            ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
                    helloformstuff.this, R.array.state_array, android.R.layout.simple_spinner_item);
            adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spState.setAdapter(adapter2);

          //Log the end of the this code
            Log.i("DrewDebug", "END Next Code");
            }
        });
    }

    if (btnBack != null) {
        //If btnBack was hit
        btnBack.setOnClickListener(new OnClickListener() {
            public void onClick(View v){
                Log.i("DrewDebug", "Button Hit: Back");
                //Log the beginning of this code 
                Log.i("DrewDebug", "BEGIN Back Code");
                //Change to first screen
                setContentView(R.layout.main);

                //Drunk Spinner
                Spinner spLevel = (Spinner) findViewById(R.id.spLevel);
                ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                        helloformstuff.this, R.array.drunk_array, android.R.layout.simple_spinner_item);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                spLevel.setAdapter(adapter);

                //Log the end of the this code
                Log.i("DrewDebug", "END Back Code");
            }
        });
    }
}
}

main.xml

<EditText 
    android:id="@+id/txtQuote" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:text="Enter Quote" /> 

<TextView 
    android:id="@+id/lblWho" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:layout_below="@id/txtQuote"
    android:text="Who Said It?"/>

<EditText 
    android:id="@+id/txtFirst" 
    android:layout_width="250px"
    android:layout_height="wrap_content" 
    android:layout_below="@id/lblWho"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="10dip"
    android:text="Anonymous" />

<EditText 
    android:id="@+id/txtLast" 
    android:layout_width="50px"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/txtFirst"
    android:layout_alignTop="@id/txtFirst"
    android:text="X"/>

<Spinner 
    android:id="@+id/spLevel"
    android:prompt="@string/drunk_prompt" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_below="@id/txtFirst"
    android:layout_alignParentLeft="true"/>

<Button 
    android:id="@+id/btnNext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_below="@id/spLevel"
    android:layout_alignParentRight="true"
    android:text="Next"/>

second.xml

<TextView 
    android:id="@+id/lblShare" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:text="Who's Sharing?"/>

<EditText 
    android:id="@+id/txtFirstShare" 
    android:layout_width="250px"
    android:layout_height="wrap_content" 
    android:layout_below="@id/lblShare"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="10dip"
    android:text="Anonymous" />

<EditText 
    android:id="@+id/txtLastShare" 
    android:layout_width="50px"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/txtFirstShare"
    android:layout_alignTop="@id/txtFirstShare"
    android:text="X"/>

<EditText 
    android:id="@+id/txtCity" 
    android:layout_width="250px"
    android:layout_height="wrap_content"
    android:layout_below="@id/txtLastShare"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="10dip"
    android:text="NoWhere"/>

<Spinner 
    android:id="@+id/spState"
    android:prompt="@string/state_prompt" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/txtCity"
    android:layout_alignTop="@id/txtCity"/>

<Button 
    android:id="@+id/btnSubmit" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_below="@id/spState"
    android:layout_alignParentRight="true"
    android:text="Submit"/>

<Button 
    android:id="@+id/btnBack" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/btnSubmit"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@id/btnSubmit"
    android:text="Back"/>

string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Random Drunk Quotes</string>
<string name="drunk_prompt">Level of Buzz</string>
<string-array name="drunk_array">
    <item>One Beer Syndrome</item>
    <item>Buzzed</item>
    <item>Drunk</item>
    <item>Trashed</item>
    <item>Retarded</item>
</string-array>

<string name="state_prompt">State</string>
<string-array name="state_array">
                  <item>AL</item> 
                  <item>AK</item> 
                  <item>AS</item> 
                  <item>AZ</item> 
                  <item>AR</item> 
                  <item>CA</item> 
                  <item>CO</item> 
                  <item>CT</item> 
                  <item>DE</item> 
                  <item>DC</item> 
                  <item>FM</item> 
                  <item>FL</item> 
                  <item>GA</item> 
                  <item>GU</item> 
                  <item>HI</item> 
                  <item>ID</item> 
                  <item>IL</item> 
                  <item>IN</item> 
                  <item>IA</item> 
                  <item>KS</item> 
                  <item>KY</item> 
                  <item>LA</item> 
                  <item>ME</item> 
                  <item>MH</item> 
                  <item>MD</item> 
                  <item>MA</item> 
                  <item>MI</item> 
                  <item>MN</item> 
                  <item>MS</item> 
                  <item>MO</item> 
                  <item>MT</item> 
                  <item>NE</item> 
                  <item>NH</item> 
                  <item>NV</item> 
                  <item>NJ</item> 
                  <item>NM</item> 
                  <item>NY</item> 
                  <item>NC</item> 
                  <item>ND</item> 
                  <item>MP</item> 
                  <item>OH</item> 
                  <item>OK</item> 
                  <item>OR</item> 
                  <item>PW</item> 
                  <item>PA</item> 
                  <item>PR</item> 
                  <item>RI</item> 
                  <item>SC</item> 
                  <item>SD</item> 
                  <item>TN</item> 
                  <item>TX</item> 
                  <item>UT</item> 
                  <item>VT</item> 
                  <item>VI</item> 
                  <item>VA</item> 
                  <item>WA</item> 
                  <item>WV</item> 
                  <item>WI</item> 
                  <item>WY</item> 
</string-array>

New source:

    //Listen for btnNext button click
    Button btnNext = (Button) this.findViewById(R.id.btnNext);
    Button btnBack = (Button) this.findViewById(R.id.btnBack);
    Button btnSubmit = (Button) this.findViewById(R.id.btnSubmit);

    if (btnNext!= null) {
        btnNext.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                clickNext();
            }
        });
    }
    if (btnBack != null) {
        //If btnBack was hit
        btnBack.setOnClickListener(new OnClickListener() {
            public void onClick(View v){
                clickBack();
            }
        });
    }
    if (btnSubmit != null) {
        //If btnSubmit was hit
        btnSubmit.setOnClickListener(new OnClickListener() {
            public void onClick(View v){
                clickSubmit();
            }
        });
    }
}



public void clickNext(){
    //Change to second Screen
    setContentView(R.layout.second);

    //Initialize State Spinner
    Spinner spState = (Spinner) findViewById(R.id.spState);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
            RandomDrunkQuotes.this, R.array.state_array, android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spState.setAdapter(adapter2);

    Button btnBack = (Button) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new OnClickListener() {
        public void onClick(View v){
            clickBack();
        }
    });
}
public void clickBack(){
    //Change to first screen
    setContentView(R.layout.main);

    //Drunk Spinner
    Spinner spLevel = (Spinner) findViewById(R.id.spLevel);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            RandomDrunkQuotes.this, R.array.drunk_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spLevel.setAdapter(adapter);

    Button btnNext = (Button) findViewById(R.id.btnNext);
    Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
    btnNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            clickNext();
        }
    });
}
public void clickSubmit(){

}
  • 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-22T16:35:58+00:00Added an answer on May 22, 2026 at 4:35 pm

    Your content view (main.xml) doesn’t contain definitions of btnBack and btnSubmit. Your code should look like this:

    Button btnNext = (Button) this.findViewById(R.id.btnNext);
    if (btnNext!= null) {
        btnNext.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ...
    
                //Change to second Screen
                setContentView(R.layout.second);
    
                //Initialize State Spinner
                ...
                Button btnBack = (Button) this.findViewById(R.id.btnBack);
                if (btnBack != null) {
                    //If btnBack was hit
                    btnBack.setOnClickListener(new OnClickListener() {
                        public void onClick(View v){
                            ...
                        }
                    });
                }
                Button btnSubmit = (Button) this.findViewById(R.id.btnSubmit);
                if (btnSubmit != null) {
                    //If btnSubmit was hit
                    btnSubmit.setOnClickListener(new OnClickListener() {
                        public void onClick(View v){
                            ...
                        }
                    });
                }
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all thanks for taking the time to look into this. I store
thanks for taking the time to look at my question. I've been diving into
First, thanks in advance for taking the time to read through this. I have
Thanks for taking the time to look at another of my questions. This seems
Hi there and thank you for taking the time to look into this. I'm
JAVA: First off, Thanks so much for taking the time to look at my
First off, let me thank you if you're taking the time to look at
Thanks for taking the time to read this. I have an unknown number of
first of all thanks for taking your time! I'm a junior Dev, working with
Thanks everyone for taking the time to read this. I have styled my navigation

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.