我有一个包含视图分页器的片段。在该主片段中有三个片段,它们是片段A,片段B,片段C.此代码正常运行。 然后我添加了一个新片段并通过片段A调用然后我在日志
中收到错误找不到ID为0x7f0d0083(com.app.sanyog:id / frame)的片段SearchPlaces {289bf4e#0 id = 0x7f0d0083}
主要片段:
/**
* Created by Admin on 04-06-2015.
*/
public class ContentFragment_Flight_Bkg extends Fragment {
private View view;
public ViewPager pager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.content_fragment_flight,container,false);
TabsPagerAdapter adapter = new TabsPagerAdapter(getFragmentManager());
pager = (ViewPager)view.findViewById(R.id.pager);
pager.setAdapter(adapter);
return view;
}
}
寻呼机适配器
public class TabsPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
// Tab Titles
private String tabtitles[] = new String[] { "One Way", "Round Trip", "Multicity" };
Context context;
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public Fragment getItem(int position) {
switch (position) {
// Open FragmentTab1.java
case 0:
OneWayTab fragmenttab1 = new OneWayTab();
return fragmenttab1;
// Open FragmentTab2.java
case 1:
RoundTripTab fragmenttab2 = new RoundTripTab();
return fragmenttab2;
// Open FragmentTab3.java
case 2:
MultiCityTab fragmenttab3 = new MultiCityTab();
return fragmenttab3;
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
return tabtitles[position];
}
}
片段A
public class OneWayTab extends Fragment {
private LinearLayout oneway_source,oneway_destiantion;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab3.xml
View view = inflater.inflate(R.layout.content_one_way_tab, container, false);
oneway_source = (LinearLayout)view.findViewById(R.id.oneway_source_layout);
oneway_destiantion = (LinearLayout)view.findViewById(R.id.oneway_destination_layout);
oneway_source.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SearchPlaces fragment_Flight= new SearchPlaces();
android.support.v4.app.FragmentTransaction fragmentTransaction_Flight = getChildFragmentManager().beginTransaction();
fragmentTransaction_Flight.replace(R.id.frame,fragment_Flight,"FLight_booking");
fragmentTransaction_Flight.commit();
}
});
oneway_destiantion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Utils.showToast(getActivity(),"Destiantion");
}
});
return view;
}
}
新片段(从片段A调用)
public class SearchPlaces extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
View view = inflater.inflate(R.layout.content_search_places, container, false);
return view;
}
}