Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 识别当前标签或edittext中的标签_Android_Mysql_Tags_Android Edittext_Hashtag - Fatal编程技术网

Android 识别当前标签或edittext中的标签

Android 识别当前标签或edittext中的标签,android,mysql,tags,android-edittext,hashtag,Android,Mysql,Tags,Android Edittext,Hashtag,我有和编辑文本,我可以写的话,标签和标签。我使用Linkify识别所有标签或hashtags,当我使用此方法按下按钮时,我可以获得所有标签: String text = editText.getText().toString(); String[] words = text.split(" "); List<String> hashtags = new ArrayList<String>();

我有和编辑文本,我可以写的话,标签和标签。我使用Linkify识别所有标签或hashtags,当我使用此方法按下按钮时,我可以获得所有标签:

            String text = editText.getText().toString();
            String[] words = text.split(" ");
            List<String> hashtags = new ArrayList<String>();
            List<String> tags = new ArrayList<String>();

            for ( String word : words) {
                if (word.substring(0, 1).equals("#")) {
                    Log.i("HASHTAG", word);
                    hashtags.add(word);
                }
                if (word.substring(0, 1).equals("@")) {
                    Log.i("TAG", word);
                    tags.add(word);
                }
            }
String text=editText.getText().toString();
String[]words=text.split(“”);
List hashtags=new ArrayList();
列表标记=新的ArrayList();
for(字符串字:字){
if(字。子串(0,1)。等于(“#”){
Log.i(“标签”,单词);
hashtags.add(word);
}
if(字子串(0,1).equals(“@”)){
Log.i(“标签”,单词);
添加(word);
}
}
现在,我想在写作时获取标签,并请求数据库向用户推荐一些单词。如何获取我插入的hashtag部分,然后进行搜索

例如,如果我写:“我认为@ta” 我想获取“ta”并在我的数据库中搜索它,然后我将用“tank”“take”“taste”填充我的listview…

您可以添加如下内容:

editText.addTextChangedListener(新的TextWatcher(){
@凌驾
public void beforeTextChanged(字符序列s、int start、int count、int after){}
@凌驾
public void onTextChanged(字符序列,int start,int before,int count){}
@凌驾
公共无效后文本更改(可编辑的s){
String text=s.toString()
if(text.lastIndexOf(“@”)>text.lastIndexOf(“”){
String tag=text.substring(text.lastIndexOf(“@”)、text.length();
//搜索标签。。。
}
}
});