Android 如何从textfield获取标记?
我在android中有一个名为TagField的文本字段。Android 如何从textfield获取标记?,android,algorithm,tags,uitextfield,Android,Algorithm,Tags,Uitextfield,我在android中有一个名为TagField的文本字段。 我有一个名为ListOfTags的字符串数组 我在Tagfield中输入几个用空格分隔的单词,并要求函数提取标记并将其存储到ListOfTags中 我想到的算法是:- 将字段中的字符串存储到字符串对象中 首先定位所有空间的位置并将其存储在数组中 使用位置从主字符串中提取子字符串 将每个子字符串存储到ListOfstring中 我的问题是,有没有更有效的方法? 因为我使用了很多数组这可以通过以下方式实现- String str = tag
我有一个名为ListOfTags的字符串数组 我在Tagfield中输入几个用空格分隔的单词,并要求函数提取标记并将其存储到ListOfTags中 我想到的算法是:-
因为我使用了很多数组这可以通过以下方式实现-
String str = tagField.getText().toString();//get string from the editText.
String[] strArray = str.split(" ");//regular expression which separates the tags.
List<String> listOfTags = Arrays.asList(strArray);
String str=tagField.getText().toString()//从编辑文本中获取字符串。
字符串[]strArray=str.split(“”)//分隔标记的正则表达式。
listOfTags=Arrays.asList(strArray);
希望这有帮助。整洁高效(y)