【问题标题】:Edittext input has lines around characters and won't deleteEdittext 输入在字符周围有线条,不会删除
【发布时间】:2013-03-22 04:49:09
【问题描述】:

我的应用程序中的编辑文本出现问题。我使用基本创建它们

etCurr = (EditText) findViewById(R.id.etCurr);
etWorth = (EditText) findViewById(R.id.etWorth);
etNeed = (EditText) findViewById(R.id.etNeed);

但是每当我运行程序并尝试输入输入时,我都会遇到这个问题

当我尝试删除输入时,当前输入并没有消失。

另外,当我尝试使用来获取编辑文本的值时

nWorth = Integer.valueOf(etWorth.getText().toString());

应用程序崩溃。

这个问题是因为使用 Swiftkey 还是我做错了什么?

编辑:当我尝试输入屏幕下方的编辑文本时,我也会遇到这个问题。这是关闭键盘后的效果。

【问题讨论】:

  • 当你使用这个 etWorth.getText().toString() 你需要确保你的edittext没有字符串字符或空字符串
  • 当我测试它时,我只输入了数字。防止字符串输入崩溃的最佳方法是什么?
  • 为您的 Edittext 设置 inputType=number

标签: android eclipse android-edittext


【解决方案1】:

试试这个,

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:singleLine="true"  <!-- use this single line -->
    android:inputType="textPersonName" >

    <requestFocus />
</EditText>

【讨论】:

  • 我将所有内容都放在了相对布局中。我的编辑文本看起来像这样 除此之外,我不太确定您还需要什么。
【解决方案2】:

试试这个,

<EditText
    android:id="@+id/etCurr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:singleLine="true"  <!-- use this single line -->
    android:inputType="number" >
    <requestFocus />
</EditText>

然后使用此代码不要从编辑文本中删除字符,

    etCurr.addTextChangedListener(new TextWatcher(){
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,int after) { etCurrBeforeText=s.toString();
        }
        @Override
        public void afterTextChanged(Editable txt) {
}
});
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{   
    if (keyCode == KeyEvent.KEYCODE_DEL) 
    {   
        if(etCurr.hasFocus())
        {
             etCurr.setText(etCurrBeforeText);
        }
    }
}

那么,

nCurr= Integer.valueOf(etCurr.getText().toString());

【讨论】:

    【解决方案3】:

    我遇到了与您描述的相同的问题。当我在每个字母后输入一些东西时,会出现一行。删除文本后,您仍然可以看到字母。只有在更改屏幕方向后,视图才会更新。在我的情况下,我做了以下修复错误:

    我的 AndroidManifest.xml 看起来像这样:

    <application ..>
      <activity .. android:theme="@style/FullscreenTheme">
      </activity>
    </application>
    

    我删除了android:theme属性,因为我过去不小心添加了一次,问题得到了解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多