小编Dei*_*son的帖子

如何在Android中创建Observable?

我想要做的是创建一个简单的内存缓存,只是为了尝试Observables.但是我被卡住了,因为我不明白如何创建一个observable.这是我到目前为止的代码:

public class MovieCache {
    MovieWrapper movieWrapper;

    public Observable<MovieWrapper> getMovies() {
       //How to create and return an Observable<MovieWrapper> here?
    }

    public void setCache(MovieWrapper wrapper) {
        movieWrapper = wrapper;
    }

    public void clearCache() {
        movieWrapper = null;
    }
}
Run Code Online (Sandbox Code Playgroud)

getMovies()方法中,我想创建一个Observable并将我的本地字段movieWrapper返回给订阅者.我怎样才能做到这一点?我尝试使用new Observable.just(movieWrapper)但它导致null异常.

android rx-java rx-android

8
推荐指数
1
解决办法
4431
查看次数

Android共享元素在带有片段的活动与带有片段的另一个活动之间转换

我有一个包含FragmentA的ActivityA,并希望将共享元素转换为包含FragmentB的ActivityB.

在活动中,共享元素将是工具栏.在片段中它将是一个textview.反正有没有这样做?

如果不是,我怎么能在活动中的两个片段之间进行共享元素转换?

在此先感谢您的帮助.我被困了一段时间.

好的,我会提供一些代码来澄清.

这里我有MainActivity:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <!-- This is shared with DetailActivity -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:transitionName="sharedToolbar"/>

    </android.support.design.widget.AppBarLayout>

    <!-- This contains MainFragment -->
    <FrameLayout
        android:id="@+id/activity_main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

此活动包含名为MainFragment的此片段:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <!-- This element is shared with DetailFragment -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Fragment main"
        android:transitionName="sharedFragment"/>

    <!-- When this is clicked show next screen -->
    <Button
        android:id="@+id/fragment_main_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Go to detail screen"
        android:layout_gravity="bottom|center"/> …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-layout android-fragments

7
推荐指数
1
解决办法
3358
查看次数