how to link a java class to a image button in eclipse?

Posted by Isabella Chan on Stack Overflow See other posts from Stack Overflow or by Isabella Chan
Published on 2012-09-10T03:21:46Z Indexed on 2012/09/10 3:38 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

I am trying to create a application that includes a Imagebutton and by clicking on the imagebutton, the application will start to run another java class that is within the package itself. I try using this method, however the program stopped working immediately? how should i code the codes instead? can anyone help me? Thanks :D

package com.fyp.gulliver;

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

public class GulliverActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //---Map button---
        Button btnMap = (Button) findViewById(R.id.map);
        btnMap.setOnClickListener(new View.OnClickListener() {
        Class ourClass; 
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {
                    ourClass = Class.forName
                        ("com.fyp.gulliver.Maps");
                    Intent ourIntent = new Intent(GulliverActivity.this, ourClass);
                    startActivity(ourIntent);
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    } 
}

© Stack Overflow or respective owner

Related posts about java

Related posts about android