我正在使用Android。我只是想优化我的代码。一般来说,我注意到很多问题都是优化的,但是由于时间有限,我们没有优化它。在这里,我分享了我的问题。基本上在所有应用程序中我都面临同样的问题。
问题
处理注册片段和EditSignUp片段的最佳方法是什么?
描述
通常在我的情况下,我制作一个registration.xml
并制作两个不同的片段RegistrationFragment.java
和EditRegistrationFragment.java
。就像下面一样。
RegistrationFragment.java
public class RagistrationFragment extends BaseFragment {
private TextView tvEmail;
private TextView tvLeaveIn;
private TextView tvUserName;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.registration, container, false);
return view;
}
public void inilialization()
{
tvUserName=(TextView)getView().findViewById(R.id.tvUserName);
tvLeaveIn=(TextView)getView().findViewById(R.id.tvLeaveIn);
tvEmail=(TextView)getView().findViewById(R.id.tvEmail);
}
EditRegistration.java
public class EditRagistrationFragment extends BaseFragment {
private TextView tvEmail;
private TextView tvLeaveIn;
private TextView tvUserName;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.registration, container, false);
return view;
}
public void inilialization()
{
tvUserName=(TextView)getView().findViewById(R.id.tvUserName);
tvLeaveIn=(TextView)getView().findViewById(R.id.tvLeaveIn);
tvEmail=(TextView)getView().findViewById(R.id.tvEmail);
tvEmail.setEnabled(false);
}
所以这里的代码不会被重用。它只是一个Example.Here我已经定义了一个初始化UI的方法,但是这个方法没有被重用。我知道你可以重用这种方法放入BaseFragment
,但这不是正确的方法,因为baseFragment将扩展Application.initialization()
中的所有Fragment只是一个例子。
我希望你清楚我的问题
请给我适当的建议。
谢谢,