Java Android子活动导航中的滑动菜单
我试图在我的应用程序中添加左侧的幻灯片菜单,但是在将幻灯片菜单添加到片段的以下子活动中时遇到了一些小问题 到目前为止,我已经尝试使用滑动菜单示例,当我现在在“FindPeople”片段类中得到这个示例时,我有静态数据 在按钮上查找人员(父活动)单击转到-->Friends(查找人员的子活动)在按钮上单击转到-->Names(朋友的子活动) 我正试图得到同样的滑动菜单与儿童活动,我也未能实现迄今为止请任何人能帮我吗Java Android子活动导航中的滑动菜单,java,android,xml,android-fragments,android-fragmentactivity,Java,Android,Xml,Android Fragments,Android Fragmentactivity,我试图在我的应用程序中添加左侧的幻灯片菜单,但是在将幻灯片菜单添加到片段的以下子活动中时遇到了一些小问题 到目前为止,我已经尝试使用滑动菜单示例,当我现在在“FindPeople”片段类中得到这个示例时,我有静态数据 在按钮上查找人员(父活动)单击转到-->Friends(查找人员的子活动)在按钮上单击转到-->Names(朋友的子活动) 我正试图得到同样的滑动菜单与儿童活动,我也未能实现迄今为止请任何人能帮我吗 public class FindPeopleFragment extends F
public class FindPeopleFragment extends Fragment {
public FindPeopleFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
Button btn = (Button) rootView.findViewById(R.id.butto);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Friends.class);
startActivity(intent);
}
});
return rootView;
}
}
朋友(儿童活动)
和类似的名称(子活动)
如何在两个子活动(朋友和姓名)中获得相同的幻灯片菜单。有什么想法吗??
请帮我解决这个问题。
代码片段将非常有用。
谢谢,正如@Piyush Gupta所说,你需要调用新片段,而不是调用活动 为了代替活动,您需要使用片段,并从一个片段移动到下一个片段 使用片段Xml的Framelayout id,而不是使用片段元素 用这个替换你的代码
public class FindPeopleFragment extends Fragment {
public FindPeopleFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
Button btn = (Button) rootView.findViewById(R.id.butto);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FragementDemo fd = new FragementDemo();
android.support.v4.app.FragmentTransaction ft =
getFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fd); // content_frame is your FrameLayout container
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
});
return rootView;
}
}
您的下一个子活动将扩展片段,而不是像这样的活动:
public class Friends extends SherlockFragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragementdemo, container, false);
// use button click code as used in FindPeopleFragment
return rootView;
}
}
希望它现在能为你工作 这样你就可以调用新的片段而不是调用活动了。这个问题解决了吗?是的,现在很好用了,谢谢,伙计!!(y) 哦..很好。。非常好。!!
public class Friends extends SherlockFragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragementdemo, container, false);
// use button click code as used in FindPeopleFragment
return rootView;
}