hellokitty 发布的帖子
已经解决了, 把数据复制一份进行修改, 再重新setDataSource就可以了
ui.run(function(){
let window = floaty.rawWindow(
<vertical w='*' bg='#FFFFFF'>
<button id='add'>添加</button>
<list id='todoList'>
<vertical>
<text text='标题' textColor='#999999' textSize='12sp' />
<text text='{{this.title}}' textColor='#222222' textSize='14sp' />
</vertical>
</list>
</vertical>
);
window.setSize(600, -2);
window.setPosition(200, 200);
let todoList = [{title: '测试1'}];
ui.run(function() {
window.todoList.setDataSource(todoList);
})
window.add.click(function() {
ui.run(function() {
let arr2 = todoList.concat();
arr2.push({title: '测试' + Math.random()});
todoList = arr2;
window.todoList.setDataSource(todoList);
})
});
})
代码如下, 我想点击"添加"按钮的时候, 加入数据到list中显示, 但是执行的时候报错Only the original thread that created a view hierarchy can touch its views, 这个该如何操作呢?
let window = floaty.rawWindow(
<vertical w='*' bg='#FFFFFF'>
<button id='add'>添加</button>
<list id='todoList'>
<vertical>
<text text='标题' textColor='#999999' textSize='12sp' />
<text text='{{this.title}}' textColor='#222222' textSize='14sp' />
</vertical>
</list>
</vertical>
);
window.setSize(600, -2);
window.setPosition(200, 200);
let todoList = [{title: '测试1'}];
ui.run(function() {
window.todoList.setDataSource(todoList);
})
window.add.click(function() {
ui.run(function() {
todoList.push({title: '测试' + Math.random()});
})
});
报错信息:
01:56:01.322/E: Wrapped android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. Expected: main Calling: ScriptThread-22[[remote]test1] (/android_asset/modules/__ui__.js#277)
Wrapped android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. Expected: main Calling: ScriptThread-22[[remote]test1]
at /android_asset/modules/__ui__.js:277:0
at /android_asset/modules/__ui__.js:271:0
at /android_asset/modules/object-observe-lite.min.js:2:0
at /android_asset/modules/object-observe-lite.min.js:2:0
at /android_asset/modules/object-observe-lite.min.js:2:0
at /android_asset/modules/object-observe-lite.min.js:2:0
通过以下代码可以获取到状态栏的高度,但是我在红米K60手机上运行的结果是84(不准确),实际高度应该是120,有什么办法能获取到正确的高度吗?
function getStatueBarHeight() {
let result = 0;
let resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}