Android Softkeyboard 在 edittext 中输入数值非常慢

标签 android soft-keyboard

我有 TableLayout,其中包含产品数量。每行包含代码、描述数量、价格、折扣值,.....取决于用户输入的数量、折扣值、折扣数量和其他一些值也会计算.

当用户点击 editText 软键盘时会出现这个也可以,工作正常

我的问题是当用户按数字键时速度非常慢以显示在 EditText 中。

例如,我从键盘上按了 3,7 或 8 秒后它只显示在那个特定的 editText 中。我怎样才能减少这个时间线...

这是我的产品图片:

ProductImage

请有人提出为什么会这样?

这样的代码:

     for (int i = initil; i <end; i++) {
        .............
        ............
        final EditText txtQty = new EditText(this);
            txtQty.setHeight(1);
            txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
            txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
            txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
            txtQty.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            txtQty.setSelectAllOnFocus(true);
            txtQty.setTextSize(9);
            txtQty.setHint("0.0");
    //      txtQty.setOnEditorActionListener(new DoneOnEditorActionListener());
//          txtQty.setHighlightColor(R.color.green);
            tr.addView(txtQty); 

            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.showSoftInput(txtQty, InputMethodManager.SHOW_IMPLICIT);

            mgr.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_IMPLICIT_ONLY);
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(txtQty.getWindowToken(), 0);

            txtQty.setOnEditorActionListener( new OnEditorActionListener() {
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    Log.i("KeyBoard" ,"Inside the Edit Text");
                    .............................
        } });

最佳答案

检查动态表格布局的代码:

主.xml:

<?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#C0C0C0">

  <RelativeLayout
     android:layout_width="fill_parent" android:paddingBottom="20dip"
     android:layout_height="fill_parent"
     android:background="#C0C0C0">

   <TableLayout android:id="@+id/contact_table"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/contact_info_title"
      android:layout_marginTop="10dp"
      android:background="@drawable/bgwhite_selector">
      </TableLayout>
 </RelativeLayout>
</ScrollView>

要添加 TableLayout 的内容,请使用此 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
      <LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/lays"
            android:layout_width="wrap_content" android:background="@color/white"
            android:layout_height="wrap_content" android:orientation="vertical"> 

<TableRow    android:background="@color/white" android:layout_width="wrap_content"
            android:layout_height="wrap_content">

<TextView   android:text=">" 
            android:textSize="18dip" android:textStyle="bold"  android:layout_width="wrap_content" 
            android:layout_height="wrap_content" android:id="@+id/arrowText"/> 
  </TableRow>

 </LinearLayout>

为布局创建单独的行后,在 Java 代码中添加:

contact_table = (TableLayout)findViewById(R.id.contact_table);

LayoutInflater inflater = getLayoutInflater();

for(int i = 0; i < contact_count ; i++) {
LinearLayout row = (LinearLayout)inflater.inflate(R.layout.table_row,contact_table, false);
TextView text = (TextView)row.findViewById(R.id.text);
text.setText(list_data.get(i).summary);
contact_table.addView(row);
  }

 for(int i=0;i<contact_table.getChildCount();i++){ 
final View row=contact_table.getChildAt(i);
row.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v){
        // TODO Auto-generated method stub
        row_id=contact_table.indexOfChild(row);
    }
});
}

第二个 for 是点击 Dynamically created Table row 的循环,在其中添加

    msg_title_text.setOnEditorActionListener(new DoneOnEditorActionListener());

对应的 Action 监听器:

    class DoneOnEditorActionListener implements OnEditorActionListener {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            Log.v("*****************************", "Clicked");

            return true;    
        }
        return false;
    }
}

关于Android Softkeyboard 在 edittext 中输入数值非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683154/

相关文章:

android - 重命名日期选择器中的默认按钮(android)

android - RecyclerView : Animate item resize

android - Espresso - 每次测试方法后 Activity 都会关闭。有没有办法我们不能停止关闭 Activity 和运行其他测试方法

android - 弹出窗口打开时软键盘未打开

c# - 如何在 WP 8.1 中获得软键盘下方的按钮?

android - 如何使用robotium单击软键盘的完成按钮?

java - 通过签名比较 SSL 证书 : is it enough?

android - Fabric 上的每日新用户数量始终远高于 Play Console 上的设备安装量

android - 如何检查是否使用了 native /硬件键盘?

android - 自定义键盘 - 无法识别启动 Activity : Default Activity not found