【问题标题】:How to get tags from textfield?如何从文本字段中获取标签?
【发布时间】:2013-12-24 06:02:41
【问题描述】:

我在 android 中有一个名为 TagField 的文本字段。
我有一个名为 ListOfTags 的字符串数组。

我在 Tagfield 中输入了几个用空格分隔的单词,并要求函数提取标签并将其存储到 ListOfTags 中。

我想到的算法是:-

  1. 将字段中的字符串存储到字符串对象中
  2. 首先定位所有空间的位置并将其存储在一个数组中
  3. 使用位置从主字符串中提取子字符串
  4. 将每个子字符串存储到 ListOFStrings 中

我的问题是,有没有更有效的方法?
由于我使用了很多数组

【问题讨论】:

    标签: android algorithm tags uitextfield


    【解决方案1】:

    这可以实现为-

    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);
    

    希望这会有所帮助。

    【讨论】:

    • 整洁高效(y)
    猜你喜欢
    • 1970-01-01
    • 2015-10-06
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2016-12-26
    相关资源
    最近更新 更多