У меня есть фрагмент с двумя кнопками внутри. Я не могу прикрепить кнопки xml к кнопкам java, потому что в классе SherlockFragment findViewById не распознается как метод.findViewById не распознан как метод в пределах Шерлок Фрагмент
Я поменял SherlockFragment на SherlockFragmentActivity, но таким образом метод OnCreateView не подходит для работы, и я не знаю, какой метод мне использовать вместо этого?
Вариант 1: findViewById не распознается как метод
public class MyProfileActionButtonsFragment extends SherlockFragment {
private Button bMyProfileEditProfile;
private Button bMyProfileSettings;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.my_profile_action_buttons_fragment, container, false);
bMyProfileEditProfile = (Button) findViewById(R.id.bMyProfileEditProfile);
bMyProfileSettings = (Button) findViewById(R.id.bMyProfileSettings);
bMyProfileEditProfile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent editUserProfile = new Intent (getActivity(), UserProfileEdit.class);
startActivity(editUserProfile);
}
});
bMyProfileSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent settings = new Intent (getActivity(), Settings.class);
startActivity(settings);
}
});
}
Вариант 2: Метод onCreateView (LayoutInflater, ViewGroup, Пачка) типа MyProfileActionButtonsFragment необходимо переопределить или реализовать метод супертипом
public class MyProfileActionButtonsFragment extends SherlockFragmentActivity {
private Button bMyProfileEditProfile;
private Button bMyProfileSettings;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.my_profile_action_buttons_fragment, container, false);
bMyProfileEditProfile = (Button) findViewById(R.id.bMyProfileEditProfile);
bMyProfileSettings = (Button) findViewById(R.id.bMyProfileSettings);
что не так? почему это вниз? – Raghunandan
Огромное вам спасибо –
@ J.Kowalski приветствую вас и рад, что это помогло, но какой-то пользователь отказался без причины, и я не вижу ничего плохого в ответе – Raghunandan