我在玩弄 MutableLiveData 的方法来找出什么触发了观察者,什么没有。
现在,我有这个活动:
class ActivityA : AppCompatActivity() {
private val liveData = MutableLiveData<Int>().apply { this.value = 10 }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
liveData.observe(this, Observer {
Log.v("ActivityA", "liveData = $it")
})
Log.v("ActivityA", "liveData = ${liveData.value}")
liveData.value = 11
liveData.postValue(12)
liveData.value = 13
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下:
liveData = 10
liveData = 13
liveData = 12
Run Code Online (Sandbox Code Playgroud)
不应该是这个吗?
liveData = 10
liveData = 11
liveData = 13
liveData = 12
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <limits.h>
typedef struct item {
int low; int high; char label[16];
} Item;
typedef struct item_coll {
size_t length; Item *items[];
} ItemColl;
char *find_first_in_range(ItemColl *ic, int rlow, int rhigh) {
for (size_t i = 0; i < ic->length; i++)
if (ic->items[i]->low >= rlow && ic->items[i]->high <= rhigh)
return &ic->items[i]->label[0];
return NULL;
}
int main() {
struct item fruits[] = {
{10, 20, "Apple"},
{12, 14, "Pear"},
{8, 12, "Banana"},
{2, 4, "Grape"},
{15, 35, "Watermelon"}
}; …Run Code Online (Sandbox Code Playgroud) 在此处调试此代码段时:
int main () {
char str[] = "Stackoverflow";
char a = *str;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么a显示为83 'S'?