所以我有MAIN ACTIVITY(M)
,兩個FRAGMENTS(F1, F2)
和BUTTON(B)
F1
。沒有發現id,同時調用子片段
現在,當主要活動啓動F1
被自動加載這是很好的,我想要做的就是開始F2
當我點擊B
這是對F1
。
以下是我的片段1代碼,HomeFragment:
package info.androidhive.slidingmenu;
import java.lang.reflect.Field;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
public class HomeFragment extends Fragment {
public static HomeFragment newInstance()
{
return new HomeFragment();
}
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
ImageButton ib = (ImageButton) rootView.findViewById(R.id.buttonEnq);
ib.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
InfoFragment infoFragment = new InfoFragment();
/*FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.frame_container, infoFragment).commit();
*/
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.abc_slide_out_bottom, 0);
ft.replace(R.id.frame_container,infoFragment);
ft.commit();
}
});
ViewPager viewPager = (ViewPager)rootView.findViewById(R.id.myfivepanelpager);
ImageAdapter adapter1 = new ImageAdapter(this.getActivity());
viewPager.setAdapter(adapter1);
return rootView;
}
@Override
public void onDetach(){
super.onDetach();
try{
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this,null);
}catch(NoSuchFieldException e){
throw new RuntimeException(e);
}catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
frame_container
在main_activity.xml
容器的名稱。我曾嘗試以下職位:
- Android Fragment no view found for ID?
- No view found for id 0x7f090005
- No view found for id for fragment
你能告訴我什麼,我做錯了什麼?
發佈您的fragment_home佈局和主要活動代碼 – Libin