Devin Tripp
Devin Tripp

Reputation: 147

cannot open another activity with a button

So when this code runs I get no errors it displays the buttons correctly and everything, but when I click on the button nothing happens it just clicks and clicks and clicks nothing happens below I will post XML manifest code so you can see that I have done everything perfectly, but somehow it it is not doing the correct thing that I am asking it to do. I've tried everything i've asked this question multiple times each time the person who answered was wrong i will post my whole new project with the minimal amount of code with only 3 classes i'm thinking something may be wrong with my settings because this doesn't work on both of my computers here is the main class code or the "launcher" thank you all for your help and have a nice day.

    package com.tripp.funnystuff;

    import android.os.Bundle;
    import android.support.v7.app.ActionBarActivity;
    import android.view.Menu;
    import android.view.MenuItem;


     public class Main extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

and here is the the menu class

package com.tripp.funnystuff;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by Devin on 3/27/2015.
 */
public class Menu extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //setting up the button references
        Button jokeD = (Button) findViewById(R.id.jokeoftheday);
        //Button jokeC = (Button) findViewById(R.id.jokecatagories);

        jokeD.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent(Menu.this, JokeOfTheDay.class);


                startActivity(i);

            }
        });

        /*jokeC.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent s = new Intent(Menu.this, JokeCatagories.class);

                Menu.this.startActivity(s);

            }
        });
        */

    }

    @Override
    protected void onPause() {

        // TODO Auto-generated method stub
        super.onPause();
    }
}

and here is the joke of the day class

package com.tripp.funnystuff;

import android.app.Activity;
import android.os.Bundle;

/**
 * Created by Devin on 3/27/2015.
 */
public class JokeOfTheDay extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jokeoftheday);
    }
}

here is the xml main code

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"  


    tools:context=".Main">


    <Button
        android:id="@+id/jokeoftheday"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textStyle="bold"
        android:text="joke of the day"/>

    </RelativeLayout>

here is the jokeoftheday xml code below

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

and last, but not least here is the manifest code

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tripp.funnystuff" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Menu"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".JokeOfTheDay"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

Please i want serious inquiries only if you want to edit my english then i will un-edit it i want help with my code not my english. so go somewhere else with your ****. ive have spent a straight week and a half on my computer looking for this problem on the internet and have found no solution if anyone has ever had this same problem please give me some kind of lead on how to solve it. I really appreciate everyone who has read this through and all the smart programmers who will take the time to help me. Thanks!

Upvotes: 0

Views: 100

Answers (1)

Bill Mote
Bill Mote

Reputation: 12823

Your Main.java is displaying the button, but has no click listener. Menu.java is unnecessary and you really should take a look at the developer's site examples.

Upvotes: 1

Related Questions