Android mosby访问来自演示者的视图

时间:2017-06-05 09:24:04

标签: android mosby

我想访问来自演示者的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 {
}

1 个答案:

答案 0 :(得分: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);}
}