具有双向数据绑定的EditText上的SelectAll

时间:2018-11-20 13:02:38

标签: android data-binding android-edittext selectall two-way-binding

我有一个带有片段的活动...在这个片段中,我在EditText中使用双向DataBing。此EditText绑定到对象的Double属性,因此,我必须实现一个InverseMethod来转换String-> Double和Double-> String ...

在我的EditText中,我配置了 android:selectAllOnFocus =“ true” ,并且还将其强制应用于片段的onCreateView方法: edQtd.selectAll() < / p>

问题是,当出现片段时,EditText成为焦点,但未选择文本,而是光标在第一个数字之前...

我希望它与所有选定的文本一起显示...

尝试连接而不是使用inverse方法,只是连接一个空的String,但是结果是相同的...

从我看到的对其进行调试的角度来看,生成的绑定类在片段创建后设置了文本(在我手动调用 edQtd.selectAll()之后),删除了选择...

有什么办法解决吗?

编辑: 现在,我解决了将TextChangedListener添加到EditText的问题,仅在第一次更改文本时,我才选择所有文本:

edQuantidade.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            if(getSelectAllEdQtdText()) {
                edQuantidade.selectAll();
                setSelectAllEdQtdText(false);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

1 个答案:

答案 0 :(得分:0)

在版式的EditText上添加以下属性。

{
  "size": 0,
  "aggs": {
    "length": {
      "terms": {
        "script": {
          "source": "params._source.vendors.length",
          "lang": "painless"
        }
      }
    }
  }
}

然后从代码中删除<EditText android:focusable="true" android:focusableInTouchMode="true" android:selectAllOnFocus="true" />

修改

因为没有一种解决方案有效。这将起作用,因为这将在延迟后触发selectAll。在绑定中设置模型后添加。

edQtd.selectAll()
相关问题