public void onClick(View v) {
Toast.makeText(MainActivity.this,"You taped!",Toast.LENGTH_SHORT).show();
try {
startActivity(new Intent(MainActivity.this, FuelChoiceActivity.class));
}catch (Exception e){
System.out.println(e);
}
}
这是我的代码。我已将新活动添加到manifest.xml中。 try / catch块没有返回任何exeption。当我按下按钮时,执行并显示吐司,但页面没有变化。这个onClickListener位于一个适配器方法' getView'所以它可以通过适配器生成的任何按钮获得。我尝试过其他活动,他们的工作!唯一没有的就是进入新的活动。
当我调试并点击按钮时,这是我的日志:
D/AbsListView: reportScrollStateChange: newState = 0, mLastScrollState = 0, mOnScrollListener = null, mScrollY = 0, mTouchMode = -1, mFirstPosition = 0
V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
D/ActivityThread: ACT-AM_ON_PAUSE_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy@32487069
D/AbsListView: onWindowFocusChanged: hasWindowFocus=false, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview}
D/OpenGLRenderer: Flushing caches (mode 0)
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
V/ActivityThread: Handling launch of ActivityRecord{1ff7b407 token=android.os.BinderProxy@19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}
V/ActivityThread: ActivityRecord{1ff7b407 token=android.os.BinderProxy@19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}: app=android.app.Application@a0dbe1c, appName=com.example.stamatis.redhotpepper, pkg=com.example.stamatis.redhotpepper, comp={com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}, dir=/data/app/com.example.stamatis.redhotpepper-1/base.apk
D/ActivityThread: ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{1ff7b407 token=android.os.BinderProxy@19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}
D/ActivityThread: ACT-PAUSE_ACTIVITY_FINISHING handled : 0 / android.os.BinderProxy@19bbf934
V/ActivityThread: Performing resume of ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-AM_ON_RESUME_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
V/ActivityThread: Resume ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} started activity: false, hideForNow: false, finished: false
V/ActivityThread: Resuming ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} with isForward=true
V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{dfe4562 com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{1d6eaa25 V.E..... R.....I. 0,0-480,782}
V/ActivityThread: Scheduling idle handler for ActivityRecord{2c1d62f0 token=android.os.BinderProxy@32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-RESUME_ACTIVITY handled : 1 / android.os.BinderProxy@32487069
D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview}
V/InputMethodManager: onWindowFocus: com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} softInputMode=272 first=false flags=#1810100
D/ActivityThread: ACT-DESTROY_ACTIVITY handled : 1 / android.os.BinderProxy@19bbf934
D/OpenGLRenderer: Flushing caches (mode 0)
D/OpenGLRenderer: Flushing caches (mode 0)
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
感谢阅读和你的时间。我很感激你的想法。
答案 0 :(得分:-1)
我的主要活动是活动
public class MainActivity extends Activity
在这项活动中,我试图转移到另一个扩展 AppCombatActivity 类。
public class FuelChoiceActivity extends AppCombatActivity
所以语法和一切都是正确的。所以我改变了FuelChoiceActivity(我想要移动的活动)延伸到:
public class FuelChoiceActivity extends Activity
如果他们都不扩展同一个类,似乎你不能转移到另一个活动。