2015-07-21 30 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

崩溃时的堆栈跟踪是什么? –