我有一個片段類 ,我有一個線性佈局可點擊 和一個按鈕可點擊。如何從片段調用兩個不同的片段
所以我想知道,當我點擊的線性佈局應啓動片段1 ,當我點擊按鈕,它應該開始片段2
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
LinearLayout l = (LinearLayout) rootView.findViewById(R.id.line1);
l.setOnClickListener(this);
Button b = (Button) rootView.findViewById(R.id.map_button);
b.setOnClickListener(this);
return rootView;
}
@Override
public void onClick(View v) {
Fragment frag = new Fragment1();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.frame_container, frag);
ft.addToBackStack(null);
ft.commit();
Fragment frag = new Fragment2();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.frame_container, frag);
ft.addToBackStack(null);
ft.commit();
現在會發生什麼? –