在我们的团队中,我们通过为视图创建一个新类来将UI逻辑与活动或片段分开,然后让活动/片段仅管理生命周期,这是否是一个好习惯?
public abstract class BaseView implements ViewInterface {
protected View rootView;
protected Context contextInterface;
private TextView nameTextView;
public BaseView(Context contextInterface, LayoutInflater inflater, ViewGroup container) {
this.contextInterface = contextInterface;
rootView = inflater.inflate(R.layout.fragment_recycler, container, false);
nameTextView=rootView.findViewById(R.id.tv_user_name);
}}
我们根据这篇文章决定了这一点:https://www.techyourchance.com/activities-android/