我有一个 EditText,它在键入时响应很慢。滞后很烦人,让我找到了解决办法。我做了一些研究并找到了一个 SO 线程 EditText lagging when typing text它建议将代码移动到它自己的线程。我做到了,但我仍然遇到滞后。
编辑
看到下面的评论后(感谢 dreamtale),我知道新线程是没有必要的。但是将代码放回 onTextChanged 或 afterTextChanged 事件中仍然会导致响应缓慢。我修改了代码以反射(reflect)最新的变化:
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/right_layout_header" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:drawable="@drawable/light_bg" >
<TableRow
android:layout_width="200dp"
android:layout_height="wrap_content"
android:shrinkColumns="1">
<TextView
android:id="@+id/tvSummaryBold"
android:layout_width="wrap_content"
android:textStyle="bold"
android:gravity="left"
android:text="@string/Summary"
style="@style/IssueDetailsLabelTextView" />
</TableRow>
<TableRow
android:layout_width="200dp"
android:layout_height="wrap_content"
android:shrinkColumns="1">
<EditText
android:id="@+id/txtSummary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/SummaryDefaultText"
android:maxLength="255"
android:singleLine="true"
android:layout_weight="1"
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/tvCharactersRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/Gray"
android:paddingLeft="5dp"
/>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
这是该 fragment 的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try
{
vView = inflater.inflate(R.layout.submit_issue, container, false);
//Setup initial "characters remaining" text.
mCharsRemaining = (TextView)vView.findViewById(R.id.tvCharactersRemaining);
mCharsRemaining.setText(String.valueOf(iMaxChars) + ' ' + getString(R.string.CharsRemaining));
//Event for counting the characters remaining.
mSummaryEditText.addTextChangedListener(TextEditorWatcher);
new LoadPOCsTask().execute();
}
catch (Exception e)
{
Errors.LogError(e);
}
return vView;
}
TextEditorWatcher 事件:
private final TextWatcher TextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
int iMaxCharsRemaining = (iMaxChars - s.length());
mCharsRemaining.setText("Static Text "); //Intentionally put static text to see if problem still occurs, and yes it does.
}
public void afterTextChanged(Editable s) {
}
};
我不明白为什么它在打字时仍然滞后。如果我删除 addTextChangeListener 事件,它就可以正常工作。想法?
最佳答案
我在 ListView 中使用 EditText 时遇到了类似的问题,通过将 EditText 宽度 更改为 0dp<> 使用加权宽度来匹配/填充父级。
我不确定为什么会发生这种情况,但我相信这是因为当 EditText 的宽度设置为包装内容时,它会自行调整/重绘以适应所有内容, ListView 也将尝试重绘自身以适应一切。因此,通过使 EditText 具有固定宽度,不再需要重绘。
关于android - EditText 输入速度很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9891826/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
这是针对我无法破坏的现有公共(public)API,但我确实希望对其进行扩展。目前,该方法采用字符串或符号或任何其他在作为第一个参数传递给send时有意义的内容我想添加发送字符串、符号等列表的功能。我可以只使用is_a吗?数组,但还有其他发送列表的方法,这不是很像ruby。我将调用列表中的map,所以第一个倾向是使用respond_to?:map。但是字符串也会响应:map,所以这行不通。 最佳答案 如何将它们全部视为数组?String的行为与仅包含String的Array相同:deffoo(obj,arg)[*arg].eac
我的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
我正在为我的用户实现一些rubyonrails代码推特内容。我正在创建正确的oauth链接...类似http://twitter.com/oauth/authorize?oauth_token=y2RkuftYAEkbEuIF7zKMuzWN30O2XxM8U9j0egtzKv但在我的测试帐户授予对twitter的访问权限后,它会弹出一个页面,上面写着“您已成功授予对.我不知道用户应该在哪里输入此PIN以及他们为什么必须这样做。我认为这不是必要的步骤。Twitter应该将用户重定向到我在应用程序设置中提供的回调URL。有谁知道为什么会这样?更新我找到了thisarticle声明我需
我相信我对这个问题有一个很好的答案,但我想确保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中使用正则表达式
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
我一直在尝试使用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:但是在输入之后整个事情就挂起。有人会碰巧知道它为
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。在我在网上找到的每个基准测试中,Ruby似乎都很慢,比Java慢得多。Ruby的人只是说这无关紧要。您能举个例子说明RubyonRails(以及Ruby本身)的速度真的无关紧要吗?
我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如
我正试图在Rails中获得完整的页面缓存,但我在CSRF方面遇到了很大的障碍——或者可能只是我对它的理解。我目前有form_authenticity_token存储在cookie中的字符串,JS可以使用该cookie访问和重写header标签。我在生成的HTML中有两个地方可以找到标记:1)在头部2)在表单的隐藏输入元素中如前所述,这些哈希值彼此不同(在未启用缓存的开发模式下)。他们为什么不同?为什么我可以删除headmeta标签并保留表单输入并且允许请求?然而,当我删除表单输入标签并保留标题时,请求被拒绝了吗?实际上这意味着head标签是无用的,不是吗?我可以将表单输入标签重写为