我在Java編程中還是比較新,我想用幾個按鈕打開一個片段不同的活動。不過,我總是得到一個錯誤(...在已定義...)在以下位置:在帶有幾個按鈕的片段中開始活動
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
在其它變型中,沒有工作
也有人甚至更多的錯誤。
這裏是我的片段全碼:
public DashboardFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);
ImageButton button = (ImageButton) rootView.findViewById(R.id.stundenplanbtn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), Stundenplan.class);
startActivity(intent);
}
});
return rootView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);
ImageButton button2 = (ImageButton) rootView.findViewById(R.id.vertretungsbtn);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), Vertretungsplan.class);
startActivity(intent);
}
});
return rootView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_dashboard, container, false);
ImageButton button2 = (ImageButton) rootView.findViewById(R.id.essenbtn);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), Essen.class);
startActivity(intent);
}
});
return rootView;
}
}
你會得到什麼錯誤? – moondaisy