Fragment 클래스에 ActionBar를 추가하고 싶지만 오류가 계속 발생합니다.getActionBar()가 정의되지 않았습니다.
The method getActionBar() is undefined for the type TaskDetailFragment
Fragment 클래스에 ActionBar를 추가하고 싶지만 오류가 계속 발생합니다.getActionBar()가 정의되지 않았습니다.
The method getActionBar() is undefined for the type TaskDetailFragment
지금까지 내가, 당신이 ActionBar
의 Activity
을 (이에 Fragment
가 부착 된) 요청해야 알고 : 당신이 지원 라이브러리 및/또는 ActionBarSherlock의를 사용하는 경우
ActionBar actionBar = getActivity().getActionBar();
또는를 :
ActionBar actionBar = getFragmentActivity().getSupportActionBar();
파편은 getActionBar()
있어서, 따라서 에러 메시지를 정의하지 않는다.
getActionBar()가 정의하는 "보호"를 추가 할 수 있습니다 TaskDetailFragment 또는 다른 수퍼 클래스 또는 때때로 안드로이드 emulataor에 정의되어 있는지 확인이 내 오류가
public class TaskDetailFragment extends Fragment {
public static final String ARG_ITEM_ID = "item_id";
MyTasks.taskItem mItem;
public TaskDetailFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_ITEM_ID)) {
mItem = MyTasks.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_task_detail,
container, false);
ActionBar actionBar = getActionBar();
actionBar.show();
if (mItem != null) {
//Add TexViews
((TextView) rootView.findViewById(R.id.in_Name))
.setText(MyTasks.customers[(Integer.parseInt(mItem.id))][1]);
((TextView) rootView.findViewById(R.id.in_Address))
.setText(MyTasks.customers[(Integer.parseInt(mItem.id))][3] + " " + MyTasks.customers[(Integer.parseInt(mItem.id))][2]);
}
return rootView;
}
}
: 이것은 내 클래스
조각에서 ActionBar를 사용하려는 경우 setHasOptionsMenu(true)
(보통 onCreate()
)을 호출해야합니다.
나는 setHasOptionsMenu (true)를 호출하면 여전히 같은 오류가 발생합니다. – ObAt