0

i have gotten it to launch the splash screen then go to the main menu, but i can't seem to get my image button to take me to the next screen(it stops working), if you'd kindly help i'd much appreciate it. The following is my manifest:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.iimed.www"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="18"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="org.iimed.www.Splashscreen"
            android:label="@string/app_name" 
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />            
</intent-filter> 

             </activity>                 

        <activity  
            android:name="org.iimed.www.MainActivity"
             android:label="@string/app_name">

        </activity>

        <ImageButton
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:onClick="myClickHandler"
        android:src="@drawable/ic_launcher" android:contentDescription="@id/button"/>


        <activity
            android:name="org.iimed.www.vpbox"
            android:label="@string/app_name">

            </activity>



       </application>








</manifest>enter code here

Here is my MainActivity java

package org.iimed.www;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.view.View.OnClickListener;
import android.content.ComponentName;




public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        ImageButton btn = (ImageButton) findViewById(R.id.button);

        btn.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v){
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(new ComponentName("org.iimed.www,","org.iimed.www.vpbox"));
                startActivity(intent);
            }
        });

}
}

Here is the java for the screen i wish the button to take me to :

package org.iimed.www;

import android.os.Bundle;
import android.app.Activity;
public class vpbox extends Activity {

    public void onCreate(Bundle vpbox_activity) {

        setContentView(R.layout.vpbox_activity);

}



    }
ToeKnee
  • 47
  • 1
  • 10

2 Answers2

0

Try this way:

btn.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v){

            startActivity(new Intent(MainActivity.this, vpbox.class));
        }
    });

Also remove, the ImageButton code from the manifest file, if you have it.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
  • Ok, thanks guys i've taken all the imagebutton code out the manifest file, and i've try the new code in the mainactivity, but it's giving me the following error "The constructor intent(new view.Onclicklistener(){},class )is undefined" also where exactly in the vpbox.class do i put the super.oncreate(savedinstance); code? – ToeKnee Oct 13 '13 at 07:09
  • ok so i have gotten rid of that error, but it's still crashing when i click the imagebutton, where do i put the super.oncreate code? – ToeKnee Oct 13 '13 at 07:16
0

First Problem: You add the ImageButton tag in your manifest file. This should be inside your activity_main.xml layout. Solve: Cut the ImageButton tag from your manifext file and paste it in your activity_main.xml page which is inside your layout folder.

2nd step: Inside your OnClickListener Change:

btn.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v){
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setComponent(new ComponentName("org.iimed.www,","org.iimed.www.vpbox"));
            startActivity(intent);
        }
    });

To

btn.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v){
            Intent intent = new Intent(this, vpbox.class);
            startActivity(intent);
        }
    });

Inside onCreate of your vpbox class add a super statement like the MainActivity..

super.onCreate(vpbox_activity);

if these things are not helping you then check your vpbox_activity.xml ..

For return from vpbox to mainactivity ,just add a button or imagebutton in your vpbox.xml same as activity_main.xml. and write the onclick code in tour vpbox.java same as mainactivity ..just made a single change in your intent path like ";

Intent intent = new Intent(this, MainActivity.class);

Note: Please create different id(android:id="@+id/different from first") in your xml, otherwise R.java use the same for both for its constant.

Ranjit
  • 5,130
  • 3
  • 30
  • 66
  • Oops, i replied in the wrong box, where do i put that code in the vpbox.xml? it's still crashing upon vlicking the imagebutton – ToeKnee Oct 13 '13 at 07:19
  • in which class you want the imagebutton...as i saw you want to add the imagebutton in side mainactivity..if I.m not wrong then you have to add it inside activity_main.xml. – Ranjit Oct 13 '13 at 07:23
  • inside your onCreate() of your vpbox activity before setcontentview(..) sentence. And also delete the two lines from your ImageButton tag (android:onClick="myClickHandler" and android:contentDescription="@id/button"). – Ranjit Oct 13 '13 at 07:29
  • if you use onClick of the button programatically then no need to write it in your xml. – Ranjit Oct 13 '13 at 07:32
  • I deleted the two lines, but now the imagebutton tag is saying "missing contentdescription on image? – ToeKnee Oct 13 '13 at 07:34
  • ok its seems like you must hav to add this,, then just write it like android:contentDescription="something"; – Ranjit Oct 13 '13 at 07:36
  • the content is a string,but in your code you use the link of an id...so write a string inside this.. – Ranjit Oct 13 '13 at 07:39
  • Ah brilliant!! thank you so much for your patience buddy, really appreciate it – ToeKnee Oct 13 '13 at 07:44
  • How do i go about making a return button? can i just reverse the process on the vpbox.java like i did in the main? – ToeKnee Oct 13 '13 at 07:44
  • Done! I can't upvote you yet though because i just joined the site :/ – ToeKnee Oct 13 '13 at 08:03