gpt4 book ai didi

java - 如何在android中以编程方式使用KEY_DEL仅删除带有@的特定单词,如 "Whats App"

转载 作者:行者123 更新时间:2023-12-01 17:54:01 26 4
gpt4 key购买 nike

这是我的代码,我想使用@删除来自RecyclerView的单词

例如;

我只想删除@Tapan整个单词;

editText.setOnKeyListener(new OnKeyListener() {                 
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
//You can identify which key pressed buy checking keyCode value with KeyEvent.KEYCODE_
if(keyCode == KeyEvent.KEYCODE_DEL){

//here how can I delete whole word with @ value

}
return false;
}
});

最佳答案

请尝试这个示例:

      String str="@Hello!!! Ple@ase try the @Example for a @solution";
//Split by space
String arrStr[]=str.split(" ");
ArrayList<String>arrList=new ArrayList<>();
for(int i=0;i<arrStr.length;i++)
{
//check first character of string
if(arrStr[i].charAt(0)=='@')
{
//if start with @ remove
arrList.remove(arrStr[i]);
}
else
{
arrList.add(arrStr[i]);
}
}
Iterator it=arrList.iterator();
while (it.hasNext())
{
System.out.print(it.next()+" ");
}

当您输入**@Hello!!! Ple@ase 尝试将 @Example for a @solution** 放入此示例代码中,您将得到 **Ple@ase try the for a**
作为输出。

关于java - 如何在android中以编程方式使用KEY_DEL仅删除带有@的特定单词,如 "Whats App",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46925188/

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