gpt4 book ai didi

android - 粘贴到多个编辑文本

转载 作者:行者123 更新时间:2023-11-29 23:30:30 24 4
gpt4 key购买 nike

我有一组四个 EditText View ,用于输入 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 ,但我无法在回调中返回粘贴的文本。

我也尝试过:

覆盖乐趣 beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}

但是在粘贴的文本中我只得到 1 个字符,我猜是因为 maxLength 设置为 1。

我怎样才能达到预期的行为?

最佳答案

也许这对你有帮助

 private void pasteText() {
ClipboardManager clipboardManager = (ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);

if(clipboardManager.hasPrimaryClip()) {
ClipData.Item item = clipboardManager.getPrimaryClip().getItemAt(0);

CharSequence ptext = item.getText();
for(int i = 0 ; i <= ptext.length() ; i++){
// 4 cases and paste to 4 edittexts
}
}
}

关于android - 粘贴到多个编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52775726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com