【问题标题】:How to get a Single line of an EditText, add it to a Listview [closed]如何获取 EditText 的单行,将其添加到 Listview [关闭]
【发布时间】:2020-04-18 06:19:40
【问题描述】:

我在 EditText 中有这 2 行:

%Print "HI"%      
%Print "I love StackOverFlow"%

如何仅将这个" --)2TEXT's(-- " 添加到列表视图中?

【问题讨论】:

  • 您的意思是将edittext引号中的文本添加到列表视图中的每一行吗?如果是,请尝试 String.split("\\"")
  • 是的,想在 " " 中添加文本,但我想检查它是否是 %Print 并删除它:[ %Print " " % ]
  • 使用 String str = sourceStr.split("\\"")[1] 你会得到引号内的文字

标签: java android android-listview android-edittext


【解决方案1】:

尝试使用 String.split()。代码示例:

String multiLines = editText.getText().toString();
String[] streets;
String delimiter = "\n";

streets = multiLines.split(delimiter);

现在您有了一系列街道。 然后像这样创建一个 ArrayAdapter:

ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.list_view_items, R.id.textView, streets);

然后像这样将 arrayAdapter 附加到您的 ListView:

ListView simpleList = (ListView) findViewById(R.id.simpleListView);
        simpleList.setAdapter(arrayAdapter);

我建议切换到 RecyclerView

【讨论】:

  • 你知道怎么做吗,如果它的 %Print 去掉 "" ?
  • string.replace("\\"", "")
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多