我有一个里面有两个按钮的片段。我无法将 xml 按钮附加到 java 按钮,因为在 SherlockFragment 类中,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:MyProfileActionButtonsFragment 类型的方法 onCreateView(LayoutInflater, ViewGroup, Bundle) 必须覆盖或实现超类型方法
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);