Fragment A按钮操作FragmentB

FragmentA:

继承OnClickListener重写Onclick

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.index:
			btnClick(0);
			showDetail(0);
			break;
			
		case R.id.bingreng:
			btnClick(1);
			showDetail(1);
			break;
                 default:
			break;
		}
	}

private void showDetail(int i) {
		 FragmentManager manager = getFragmentManager();  
	        FragmentTransaction transaction = manager.beginTransaction();  
	        Fragment details = (Fragment)  
	                getFragmentManager().findFragmentById(R.id.mainFrag);  
		switch (i) {
		case 0:
			details = new MainFrag();
			transaction.replace(R.id.mainFrag, details);
			break; 
		case 1:
			details = new BrlbFrag();
			transaction.replace(R.id.mainFrag, details);
			break;
		}
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);  
                transaction.commit(); 
	}

设置以上即可替换Layout中R.id.mainFrag部分。

Layout:



    
    
  
	




你可能感兴趣的:(Android基础备份,android,layout,fragment)