我在用
Transformations.map
LiveData
基于原稿。当
getValue
null
.
实时数据
不打电话
observe
在上面?
public class LiveDataTest {
@Rule
public TestRule rule = new InstantTaskExecutorRule();
@Test
public void mapTest() {
final MutableLiveData<String> original = new MutableLiveData<>();
final LiveData<String> mapped = Transformations.map(original, input -> "Mapped: " + input);
System.out.println(original.getValue()); // null - OK
System.out.println(mapped.getValue()); // null - OK
original.setValue("Hello, World!");
System.out.println(original.getValue()); // "Hello, World!" - OK
System.out.println(mapped.getValue()); // null - Should be "Mapped: Hello, World!"
}
}