NeoVe
NeoVe

Reputation: 3897

ImageButtons not working - Android Studio

I have this WelcomeActivity where I programmed 4 ImageButtons to launch another activities.

This is my code:

public class WelcomeScreen extends Activity {

ImageButton completeprofile;
ImageButton gotoportfolio;
ImageButton findfriends;
ImageButton readnews;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome_activity);

    completeprofile = (ImageButton) findViewById(R.id.completeprofile);
    gotoportfolio = (ImageButton) findViewById(R.id.gotoportfolio);
    findfriends = (ImageButton) findViewById(R.id.findfriends);
    readnews = (ImageButton) findViewById(R.id.readnews);

    completeprofile.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
            Intent i = new Intent(WelcomeScreen.this, LoginMember.class);
            startActivity(i);
        }
    });

    gotoportfolio.setOnClickListener(new View.OnClickListener() {

         @Override
         public void onClick(View view) {
             Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
             startActivity(i);
         }
    });

    findfriends.setOnClickListener(new View.OnClickListener() {

         @Override
         public void onClick(View view) {
             Intent i = new Intent(WelcomeScreen.this, MainActivity.class);
             startActivity(i);
         }
    });

    readnews.setOnClickListener(new View.OnClickListener() {

         @Override
         public void onClick(View view) {
             Intent i = new Intent(WelcomeScreen.this, RegisterMember.class);
             startActivity(i);
         }
    });

}}

Problem is, they actually behave like buttons when I click them, but no activity is launched, this is the layout declaration:

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="70dp"
        android:layout_marginLeft="105dp">

        <ImageButton
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/completeprofile"
            android:src="@drawable/completeprofile"
            android:layout_marginLeft="75dp"
            android:contentDescription="completeprofile" />

        <ImageButton
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/gotoportfolio"
            android:src="@drawable/gotoportfolio"
            android:layout_marginLeft="65dp" />

        <ImageButton
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/findfriends"
            android:src="@drawable/findfriends"
            android:layout_marginLeft="65dp" />

        <ImageButton
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/readnews"
            android:src="@drawable/readnews"
            android:layout_marginLeft="65dp" />

    </LinearLayout>

Why is this happening? Maybe the intent launch has some issue?

Any ideas?

thanks in advance!

EDIT

Here's the manifest:

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="21"
    tools:overrideLibrary="android.support.multidex" />

<supports-screens
    android:largeScreens="true"
    android:normalScreens="false"
    android:requiresSmallestWidthDp="600"
    android:smallScreens="false"
    android:xlargeScreens="true" />

<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />

<!-- <uses-sdk  /> -->
<application
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@drawable/logo"
    android:label="Shairlook"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.kkoci.shairlook.SplashScreen"
        android:configChanges="orientation"
        android:label="Shairlook"
        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="com.kkoci.shairlook.MemberActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.RegisterMember"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.LoginMember"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.WelcomeScreen"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >

    </activity>
    <activity
        android:name="com.kkoci.shairlook.YoutubeVid"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >

    </activity>
    <activity
        android:name="com.kkoci.shairlook.ProfileMember"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.PortfolioMember"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.ForgotPassActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.MainActivity"
        android:configChanges="orientation"
        android:label="Shairlook"
        android:screenOrientation="portrait" >


    </activity>
    <activity
        android:name="com.kkoci.shairlook.WebActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo" >

    </activity>

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />
</application>

Upvotes: 0

Views: 428

Answers (2)

Anupam
Anupam

Reputation: 887

@override won't cause problem. It's quite weird if activities are added in manifest and present in same pkg.

  1. can you please add debug Log in onClick(), this will narrow down the problem whether problem is really with callback or not.

  2. try android:clickable="true"/android:focusable="true"/ android:focusableInTouchMode="true" as additional attributes for ImageButton

Hope this helps!

Upvotes: 3

edwoollard
edwoollard

Reputation: 12335

You should remove the '@Override' from above each onClick method, they are not needed and this may be causing you an issue.

Upvotes: 0

Related Questions