【问题标题】:how to remove whitspace while pasting in edittextbox?在编辑文本框中粘贴时如何删除空格?
【发布时间】:2012-05-04 19:52:00
【问题描述】:

我需要在我的应用程序的编辑框中写 "tingting"。首先我写了 ting,然后我复制了文本并将其粘贴到同一个编辑框中。但是编辑文本中的值为“ting ting”。
.我知道如何在从编辑文本中获取值时删除空格。但我想在编辑框中粘贴文本时删除空格
我怎样才能做到这一点?下面给出的是我的编辑文本框。

 <EditText
        android:id="@+id/list_AddNewtext"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="@drawable/list_stdcenterelement"
        android:imeOptions="actionSend|actionGo|actionDone"
        android:inputType="text|textCapWords"
        android:padding="5dp"
        android:textColor="@android:color/black"
        android:textSize="14sp"
        android:textStyle="bold"
        android:visibility="visible"
        android:maxLength="1000" />

【问题讨论】:

  • 我猜你手动复制粘贴它。
  • 我正在使用设备的复制和粘贴功能
  • 是否可以使用 textChangeListener 或类似的东西?
  • 没有人能解决这个问题?

标签: android android-edittext removing-whitespace


【解决方案1】:

试试

String str=list_AddNewtext.getText().trim();
list_AddNewtext.setText(str);

【讨论】:

  • 在什么情况下我必须编写此代码。当我粘贴文本时出现问题。是否有任何事件用于粘贴功能?
  • 当我添加 textwatcher 时它崩溃了 :(
  • 您想自动化复制过程吗?
【解决方案2】:

试试这个

String str = list_AddNewtext.getText().toString();
String _newstr = str.replace(" ", "");

使用 _newstr 提供 tingting 输出

你把这段代码放在你的 onclickListner 事件中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2014-10-25
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多