Activity跳转Activity,Fragment切换下一个Fragment

一、Activity跳转下一个Activity

Login.java跳转到MainActivity.java,在Login.java的OnClick方法中

Intent intent = new Intent();
intent.setClass(Login.this, MainActivity.class);
startActivity(intent);

二、Fragment1切换下一个UserInfoFragment

确定这两个Fragment所在的Activity的布局ID:R.id.main_layout,实例化UserInfoFragment的对象

ly1.setOnClickListener(new OnClickListener() {
			
		@Override
		public void onClick(View arg0) {
		    UserInfoFragment userFragment = new UserInfoFragment();		
		    FragmentTransaction transaction = getFragmentManager().beginTransaction();  
                    transaction.replace(R.id.main_layout, userFragment);  
                    transaction.addToBackStack(null);  
                    transaction.commit();
                
			}
		});





你可能感兴趣的:(android,Activity,Fragment)