jjzjj

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

coder 2023-12-14 原文

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

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

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

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

这是我的产品图片:

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

这样的代码:

     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 Softkeyboard 在 edittext 中输入数值非常慢的更多相关文章

  1. ruby-on-rails - 如果为空或不验证数值,则使属性默认为 0 - 2

    我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val

  2. ruby-on-rails - 使用 HTTParty 的非常基本的 Rails 4.1 API 调用 - 2

    Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"

  3. ruby - 鸭子输入字符串、符号和数组的优雅方式? - 2

    这是针对我无法破坏的现有公共(public)API,但我确实希望对其进行扩展。目前,该方法采用字符串或符号或任何其他在作为第一个参数传递给send时有意义的内容我想添加发送字符串、符号等列表的功能。我可以只使用is_a吗?数组,但还有其他发送列表的方法,这不是很像ruby​​。我将调用列表中的map,所以第一个倾向是使用respond_to?:map。但是字符串也会响应:map,所以这行不通。 最佳答案 如何将它们全部视为数组?String的行为与仅包含String的Array相同:deffoo(obj,arg)[*arg].eac

  4. ruby - 如何在 Ruby 中生成一个非常大的随机整数? - 2

    我想在ruby​​中生成一个64位整数。我知道在Java中你有很多渴望,但我不确定你会如何在Ruby中做到这一点。另外,64位数字中有多少个字符?这是我正在谈论的示例......123456789999。@num=Random.rand(9000)+Random.rand(9000)+Random.rand(9000)但我认为这是非常低效的,必须有一种更简单、更简洁的方法来做到这一点。谢谢! 最佳答案 rand可以将范围作为参数:pa=rand(2**32..2**64-1)#=>11093913376345012184putsa.

  5. ruby - ruby 中的同一个程序如何接受来自用户的输入以及命令行参数 - 2

    我的ruby​​脚本从命令行参数获取某些输入。它检查是否缺少任何命令行参数,然后提示用户输入。但是我无法使用gets从用户那里获得输入。示例代码:test.rbname=""ARGV.eachdo|a|ifa.include?('-n')name=aputs"Argument:#{a}"endendifname==""puts"entername:"name=getsputsnameend运行脚本:rubytest.rbraghav-k错误结果:test.rb:6:in`gets':Nosuchfileordirectory-raghav-k(Errno::ENOENT)fromtes

  6. ruby-on-rails - 为什么用户必须输入 7 位数的 Twitter PIN 才能授予我的应用程序访问权限? - 2

    我正在为我的用户实现一些ruby​​onrails代码推特内容。我正在创建正确的oauth链接...类似http://twitter.com/oauth/authorize?oauth_token=y2RkuftYAEkbEuIF7zKMuzWN30O2XxM8U9j0egtzKv但在我的测试帐户授予对twitter的访问权限后,它会弹出一个页面,上面写着“您已成功授予对.我不知道用户应该在哪里输入此PIN以及他们为什么必须这样做。我认为这不是必要的步骤。Twitter应该将用户重定向到我在应用程序设置中提供的回调URL。有谁知道为什么会这样?更新我找到了thisarticle声明我需

  7. Ruby 服务器在本地主机(teambox)之外非常慢 - 2

    我刚刚在我的Ubuntu9.10服务器上安装了TeamBox。我使用提供的服务器脚本在端口3000上启动并运行它。它的运行速度非常慢,从另一台计算机连接时每个HTTP请求最多需要30秒。我使用链接从shell加载TeamBox,一点也不花时间。然后我设置了一个SSH隧道,它再次运行得非常快。我通过此服务器上的apache以及SAMBA等运行了大约30个虚拟主机,没有任何问题。我该如何解决这个问题? 最佳答案 我的redmine(ruby,webrick)太慢了。现在我解决了这个问题:apt-getinstallmongrelruby

  8. ruby - 使用 Ruby 将输入值适本地转换为整数或 float - 2

    我相信我对这个问题有一个很好的答案,但我想确保ruby​​-philes没有更好的方法来做到这一点。基本上,给定一个输入字符串,我想在适当的情况下将该字符串转换为整数,或在适当的情况下将其转换为float。否则,只返回字符串。我会在下面发布我的答案,但我想知道是否有更好的方法。例如:to_f_or_i_or_s("0523.49")#=>523.49to_f_or_i_or_s("0000029")#=>29to_f_or_i_or_s("kittens")#=>"kittens" 最佳答案 我会尽可能避免在Ruby中使用正则表达式

  9. 【Python】判断字符串输入合法化 - 2

    Python判断字符串输入合法化只包含数字包含数字只包含中文包含中文只包含字母包含字母只包含数字判断字符串是否只包含数字:1.str.isdecimal()如果str只包含全角数字则返回True2.str.isdigit()如果str只包含全角数字、unicode编码的数字字符串例如⑴、\u00b2此类型则返回True3.str.isnumeric()如果str只包含数字(全角、半角)则返回True包含数字判断字符串是否只包含数字:print(bool(re.search(r'\d',"12321sad")))re.search()方法扫描整个字符串,并返回第一个成功的匹配,(re.searc

  10. ruby - Net::SSH sudo 命令在输入密码后挂起 - 2

    我一直在尝试使用Thor编写一个小型库,以帮助我快速创建新项目和站点。我写了这个小方法:defssh(cmd)Net::SSH.start(server_ip,user,:port=>port)do|session|session.execcmdendend只是协助我在需要时在远程服务器上运行快速命令。问题是当我需要在远程端的sudo下运行命令时,脚本似乎卡在我身上。例如当执行这个...ssh("sudocp#{file_from_path}#{file_to_path}")脚本会提示我输入密码[sudo]passwordforuser:但是在输入之后整个事情就挂起。有人会碰巧知道它为

随机推荐