閱讀「首先Android編程」,它有點過時,所以本書中顯示的代碼也過時了。 My Code錯誤的第二個參數類型與片段
Android Studio說:錯誤的第二個參數類型。 發現:com.xfunny.workout.WorkoutDetailFragment '要求:android.app.Fragment'
public class WorkoutDetailFragment extends Fragment {
private long workoutId;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_workout_detail, container, false);
}
@Override
public void onStart() {
super.onStart();
View view = getView();
if(view != null){
TextView title = (TextView) view.findViewById(R.id.textTitle);
Workout workout = Workout.workouts[(int)workoutId];
title.setText(workout.getName());
TextView description = (TextView) view.findViewById(R.id.textDescription);
description.setText(workout.getDescription());
}
}
public void setWorkout(long id){
this.workoutId = id;
}
}
請張貼代碼(不是圖片)的'WorkoutDetailFragment' – tyczj
不'WorkoutDetailFragment'擴展'Fragment'? –
是的,它擴展了片段。 –