【发布时间】:2019-03-17 11:03:30
【问题描述】:
我有一组四个 EditText 视图,用于输入 4 位代码。每一个都设置为 1 的 maxLength,因为它们包含其中一个数字。
现在我想让我的用户复制四位代码并将其直接粘贴到 4 个字段中。
我尝试使用以下方法检测粘贴事件:
@Override
public boolean onTextContextMenuItem(int id) {
boolean consumed = super.onTextContextMenuItem(id);
switch (id){
case android.R.id.cut:
onTextCut();
break;
case android.R.id.paste:
onTextPaste();
break;
case android.R.id.copy:
onTextCopy();
}
return consumed;
}
类似于this question,但我无法在回调中返回粘贴的文本。
我也尝试过:
覆盖 fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
但是在粘贴的文本中我只得到 1 个字符,我猜是因为 maxLength 设置为 1。
我怎样才能达到预期的行为?
【问题讨论】: