2015-07-21 35 views
0

我的按鈕沒有運動或顏色改變(他們應該?)他們也不按照指示(我只編碼爲一)我打算讓他們改變活動佈局,但他們並沒有這樣做。以下是有關該問題的代碼。謝謝!Android按鈕不會改變我的活動佈局

所以這裏是點擊收聽我的Java代碼:

Button lost = (Button)findViewById(R.id.lost1); 
     lost.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       startActivity(new Intent("com.guruguru2.lostnfound.FOUNDTEXT")); 
       System.out.println("pressed"); 
      } 
     }); 

和清單引用這一意圖:

<activity 
      android:name=".FoundText" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.guruguru2.lostnfound.FOUNDTEXT" /> 

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

最後,隨着按鈕的XML佈局(僅涉及部分):

<Button 
     android:id="@+id/lost1" 
     android:layout_width="fill_parent" 
     android:layout_height="230dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="top" 
     android:layout_weight="1" 
     android:text="@string/lost" 
     android:textColor="@color/lostfoundtext" 
     android:textColorLink="@color/white" 
     android:textSize="@dimen/abc_text_size_headline_material" 
     android:textStyle="bold|italic" 
     android:typeface="serif" /> 

    <Button 
     android:id="@+id/found1" 
     android:layout_width="fill_parent" 
     android:layout_height="230dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="bottom" 
     android:layout_weight="1" 
     android:text="Found" 
     android:textColor="@color/lostfoundtext" 
     android:textColorLink="@color/white" 
     android:textSize="@dimen/abc_text_size_headline_material" 
     android:textStyle="bold|italic" 
     android:typeface="serif" /> 
+0

你在用什麼? –

回答

0

打開你的活動是這樣的:

Intent intent = new Intent(); 
intent.setAction("com.guruguru2.lostnfound.FOUNDTEXT"); 
startActivity(intent); 

Intent intent = new Intent(YourActivity.this, FoundText.class); 
startActivity(intent); 
+0

我改變了它只是爲了確保,但仍然沒有改變按鈕上的活動或動畫。 – guruguru32

+0

@alashow因此,按鈕是工作,但有一個)在開始下一個活動之前大約6秒的極端滯後和b)當下一個活動開始時,屏幕變黑,應用程序崩潰。 – guruguru32

0

我只是想你的代碼有一個新的項目和它的工作就好了。當我點擊丟失按鈕時,它切換到新的活動。按鈕點擊動畫也播放。我懷疑如果按鈕沒有播放動畫並且沒有按照您的期望進行操作,那麼您的佈局可能會出現問題。

你可以驗證按鈕處理程序正在調用?嘗試在處理程序中放置一個System.out.println(),或者使用調試器並設置一個斷點。

PS: 它不會傷害任何東西,但我知道你並不需要這一行的清單,裏面的活動:

<action android:name="com.guruguru2.lostnfound.FOUNDTEXT" /> 

啓動的活動只需要活動的全名;你的活動不需要處理意圖。

+0

所以當它被點擊。什麼都沒有輸出到控制檯。我添加了一條小行,指示它這樣做:/所以處理程序沒有被調用。 – guruguru32

+0

所以按鈕正在工作,但有一個)在開始下一個活動前約6秒的極端滯後和b)當下一個活動開始時,屏幕變黑,應用程序崩潰。 – guruguru32

+0

崩潰時的堆棧跟蹤是什麼? –