订阅功能不起作用

时间:2018-06-05 17:31:09

标签: kotlin scheduler rx-java2

我正在尝试RxJava2的基础知识。

DataFrame

获得可观察的功能:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_vogella)
        setSupportActionBar(toolbar)

        val todoObserverable= createObservable();


        try {
            todoObserverable
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe ({ t-> Log.e(TAG,t.title)}, {e-> Log.e(TAG,e.localizedMessage)})

        }catch (e:Exception){
            e.printStackTrace()
        }

            }

但是我无法打印出书的标题。它没有给我任何错误或例外。 我试图调试createObservable()但是curser没有进入subscribe函数。 任何提示都会有所帮助。

1 个答案:

答案 0 :(得分:0)

public class Job : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public StateEnum State { get { return this.state; } private set { this.state = value; this.OnPropertyChanged(); } } } public class MainWindow : Window, INotifyPropertyChanged public List<Job> Jobs { get { return this.jobs; } private set { this.jobs = value; foreach(var job in this.jobs) { job.PropertyChanged += job_PropertyChanged; } } } private void job_PropertyChanged(object sender, PropertyChangedEventArgs e) { this.OnPropertyChanged("Jobs"); } } - 这实际上会在Observable.create { object :ObservableOnSubscribe<Book>{内创建ObservableOnSubscribe。对象声明是多余的,或者您可以删除lambda定义。 (ObservableOnSubscribe