我正在开发MVP架构下的应用程序,我正在使用DataBinding。我有一个ViewPager,在第一个视图页面片段中有一些TexViews
这是我的第一个片段,在ViewPager中,有TextViews,请注意setText()方法只适用于我的bind()方法,但不适用于它。
public class ViewPagerFragmentMe extends BaseFragment implements ViewPagerFragmentMeView {
private ViewPagerFragmentMePresenter mPresenter;
private FragmentViewPagerMeBinding mFragmentBinding;
private TextView mFollowers;
private TextView mFollowing;
private TextView mPost;
@Override
protected View getBindView(LayoutInflater inflater, ViewGroup container) {
mFragmentBinding = DataBindingUtil.inflate(inflater,
R.layout.fragment_view_pager_me,container,false);
View view = mFragmentBinding.getRoot();
bind(mFragmentBinding);
return view;
}
@Override
protected void getPresenter() {
Log.d(Constans.LOG,"GET PRESENTER CALLED");
mPresenter = new ViewPagerFragmentMePresenterImpl(this);
mFollowers.setText("2");//does not work
startSocialCounterUp(3,mFollowers);
}
@Override
public void startSocialCounterUp(int number, TextView textView) {
mPresenter.onSetNumberCounterUp(number,textView);
mFollowers.setText(String.valueOf(number));//does not work
}
private void bind(FragmentViewPagerMeBinding binder) {
mFollowers = binder.textViewPagerFollowersNumber;
mFollowing = binder.textViewPagerFollowingNumber;
mPost = binder.textViewPagerPostNumber;
mFollowers.setText("1");//works
}
}
这是我的BaseFragment
public abstract class BaseFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = getBindView(inflater,container);
getBindView(inflater, container);
getPresenter();
return view;
}
protected abstract View getBindView(LayoutInflater inflater, ViewGroup container);
protected abstract void getPresenter();
}
最后我的MVP视图与片段相关
public interface ViewPagerFragmentMeView {
void startSocialCounterUp(int number, TextView textView);
}
很奇怪。是不是?我做错了什么?