0

我想访问查看小部件,例如演示者TextViewEditText来自演示者,我该怎么做,

在我的活动主要中,我想更改scheduleDateTimeNotify演示者的文本

public class ActivityChannelContent extends MvpActivity<ActivityChannelContentView, ActivityChannelContentPresenter>
        implements ActivityChannelContentView{

    @BindView(R.id.scheduleDateTimeNotify)
    TextView scheduleDateTimeNotify;

    @NonNull
    @Override
    public ActivityChannelContentPresenter createPresenter() {
        return new ActivityChannelContentPresenterImpl(getApplicationContext());
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_channel_content);
        ButterKnife.bind(this);
    }
}

主持人:

public interface ActivityChannelContentPresenter extends MvpPresenter<ActivityChannelContentView> {
}

ActivityChannelContentPresenterImpl:

public class ActivityChannelContentPresenterImpl extends MvpBasePresenter<ActivityChannelContentView> implements ActivityChannelContentPresenter {
    private final ActivityChannelContentModel model;

    public ActivityChannelContentPresenterImpl(Context context) {
        model = new ActivityChannelContentModel(context);
    }
}

ActivityChannelContentViewModel:

public class ActivityChannelContentViewModel {
    private final Context context;

    public ActivityChannelContentViewModel(Context mContext) {
        context = mContext;
    }
}

ActivityChannelContentView 接口:

public interface ActivityChannelContentView extends MvpView {
}
4

1 回答 1

0

我研究过 MVP 设计模式,您可以使用 Presenter 逻辑在 View 中的 TextView 上设置文本。例如:

public interface MContract {

    interface View{
        void setText(String value)
    }

    interface Presenter extends BasePresenter {
        void addData(String value);
    }
}

public class MPresenter implements MContract.Presenter {
    private MContract.View mView;

    @Override
    public void addData(String value) {
            mView.setText(value);
    }
}

public class Activity extends AppCompatActivity  implements MContract.View {

 @Override
    public void setText(String value) {textview.setText(value);}
}
于 2017-06-05T09:41:37.093 回答