我正在創建一個帶有片段的登錄頁面,但每當我運行應用程序時,我只會得到一個白色的碎石,沒有edittext沒有按鈕的任何按鍵。調用片段時只顯示白色屏幕
LoginFragment
public class LoginFragment extends Fragment {
private View view;
private Button btcancel;
private EditText etpassword;
private Button btlogin;
private EditText etusername;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view=inflater.inflate(R.layout.login_frag,container,false);
return view;
}
private void initialize() {
btcancel = (Button) getActivity().findViewById(R.id.bt_cancel);
etpassword = (EditText) getActivity().findViewById(R.id.et_password);
btlogin = (Button) getActivity().findViewById(R.id.bt_login);
etusername = (EditText) getActivity().findViewById(R.id.et_user_name);
}
}
LoginActivity
public class LoginActivity extends Activity {
private FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentSetUp();
}
private void fragmentSetUp() {
fragmentTransaction=getFragmentManager().beginTransaction();
LoginFragment loginFragment=new LoginFragment();
fragmentTransaction.add(loginFragment,"login").commit();
}
}
它工作ty.And先生這是建議tp創建一個容器的片段? – Anuj
@Anuj對我來說,是的,它是在你的設計中創造更多的深度。 –
所以我必須創建一個不同的佈局,這將有容器? – Anuj