2015-06-27 65 views
0

我有這個WelcomeActivity我在這裏編程了4個ImageButtons來啓動另一個活動。ImageButtons不工作 - Android Studio

這是我的代碼:

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); 
     } 
    }); 

}} 

問題是,他們的行爲事實上象按鈕,當我點擊他們,但沒有活動啓動,這是佈局聲明:

<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> 

爲什麼這發生?也許意圖發佈有一些問題?

任何想法?

在此先感謝!

編輯

這裏的清單:

<?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> 

+0

我應該在被調用的活動上引用什麼嗎? – NeoVe

+2

您是否在清單中聲明活動? –

+0

當然...這很奇怪我不知道 – NeoVe

回答

0

你應該從每一個的onClick方法除去上面的 '@覆蓋',他們不需要,這可能會導致你的問題。

+0

雅與@override有一個警告,但仍然是相同的問題=( – NeoVe

+0

@NeoVe你可以發佈你的清單文件嗎?你目前的文件沒有問題,所以它一定是錯誤的文件,這裏不顯示 – edwoollard

+0

是@edwoollard,我編輯了我的問題,非常感謝! – NeoVe

3

@override不會導致問題。如果活動添加在清單中並且以相同的包裝顯示,那就太奇怪了。

  1. 請問您可以添加調試登錄onClick(),這將縮小問題是否真的是回調與否的問題。

  2. 嘗試機器人:可點擊= 「真」/機器人:可調焦= 「真」/機器人:focusableInTouchMode = 「真」 作爲附加屬性的ImageButton的

希望這有助於!

+0

嗨,要添加調試到看看會發生什麼 – NeoVe

+0

我正在調試它,但什麼也沒有發生,我刪除@override,因爲有一個警告,但仍然是同樣的問題,這些按鈕調用活動編程和宣佈清單,=/ – NeoVe

+0

也許我需要引用一些活動我在打電話? – NeoVe