Java 在操作工具栏中使用DrumerMenu的片段
问题在于,我的主要活动是由抽屉活动组成的,当我给出抽屉活动的一些选项时,我必须传递给片段,问题在于,当我传递给片段时,我失去了从片段抽屉打开菜单的选项 ` 这是java代码的主要活动 这是我想要实现抽屉的片段代码Java 在操作工具栏中使用DrumerMenu的片段,java,android,android-fragments,Java,Android,Android Fragments,问题在于,我的主要活动是由抽屉活动组成的,当我给出抽屉活动的一些选项时,我必须传递给片段,问题在于,当我传递给片段时,我失去了从片段抽屉打开菜单的选项 ` 这是java代码的主要活动 这是我想要实现抽屉的片段代码 public class Fragmen1 extends Fragment { Button HBoton; Button GBoton; Button SCTBoton ; Button RGboton ; Button CPBoton ; B
public class Fragmen1 extends Fragment {
Button HBoton;
Button GBoton;
Button SCTBoton ;
Button RGboton ;
Button CPBoton ;
Button ARBoton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fragmen1, container, false);
HBoton = (Button) view.findViewById(R.id.HipotenusaBoton);
HBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent HBoton = new Intent(getActivity(), Hipotenusa.class);
startActivity(HBoton);
}
});
GBoton= (Button) view.findViewById(R.id.button3);
GBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent GBoton = new Intent(getActivity(), Grados_Radianes.class);
startActivity(GBoton);
}
});
SCTBoton = (Button) view.findViewById(R.id.SCTboton);
SCTBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v ){
Intent SCTBoton = new Intent(getActivity(), SenoCosenoTangente.class);
startActivity(SCTBoton);
}
});
RGboton = (Button) view.findViewById(R.id.button6);
RGboton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent RGboton = new Intent(getActivity(),RadianesGrados.class);
startActivity(RGboton);
}
});
CPBoton = (Button) view.findViewById(R.id.CAPbutton);
CPBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent CPBoton = new Intent( getActivity(),CordenadasRectagularesPolares.class);
startActivity(CPBoton);
}
});
ARBoton = (Button) view.findViewById(R.id.arboton);
ARBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ARBoton = new Intent( getActivity(),AnguloReferencia.class);
startActivity(ARBoton);
}
});
return view;
}
}
看,你需要有一个抽屉供所有活动共享,所以请查看并查看答案中的链接。我使用的抽屉菜单有默认的android studioIt是相同的代码,要么你自己做,要么android Studio为你生成。
public class Fragmen1 extends Fragment {
Button HBoton;
Button GBoton;
Button SCTBoton ;
Button RGboton ;
Button CPBoton ;
Button ARBoton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fragmen1, container, false);
HBoton = (Button) view.findViewById(R.id.HipotenusaBoton);
HBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent HBoton = new Intent(getActivity(), Hipotenusa.class);
startActivity(HBoton);
}
});
GBoton= (Button) view.findViewById(R.id.button3);
GBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent GBoton = new Intent(getActivity(), Grados_Radianes.class);
startActivity(GBoton);
}
});
SCTBoton = (Button) view.findViewById(R.id.SCTboton);
SCTBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v ){
Intent SCTBoton = new Intent(getActivity(), SenoCosenoTangente.class);
startActivity(SCTBoton);
}
});
RGboton = (Button) view.findViewById(R.id.button6);
RGboton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent RGboton = new Intent(getActivity(),RadianesGrados.class);
startActivity(RGboton);
}
});
CPBoton = (Button) view.findViewById(R.id.CAPbutton);
CPBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent CPBoton = new Intent( getActivity(),CordenadasRectagularesPolares.class);
startActivity(CPBoton);
}
});
ARBoton = (Button) view.findViewById(R.id.arboton);
ARBoton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ARBoton = new Intent( getActivity(),AnguloReferencia.class);
startActivity(ARBoton);
}
});
return view;
}
}