安卓的EditText和addTextChangedListener [英] Android EditText and addTextChangedListener
问题描述
即时通讯目前正在移植一个数据库管理器Android和由于性能原因,我喜欢 仅更新已修改propertys。我试着去做到这一点的addTextChangedListener以修改entrys添加到列表,但我的计划从来没有进入它的任何方法。
的EditText的Et =(EditText上)Editors.get(Prop.Name);
Et.addTextChangedListener(新TextWatcher(){
@覆盖
公共无效afterTextChanged(编辑S){
// TODO自动生成方法存根
}
@覆盖
公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){
// TODO自动生成方法存根
}
@覆盖
公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){
// TODO自动生成方法存根
如果(Prop.GetType()== Property.PROPTYPE.num){
浮F = Float.parseFloat(s.toString());
Prop.FromString(F);
}
其他 {
Prop.FromString(s.toString());
}
propertiesToUpdate.add(道具);
});
Et.setText(Prop.ToString());
为什么得到的EditText实例这种方式。这是你的活动布局的一部分,所以你应该得到它像这样
的EditText的Et =(EditText上)findViewById(R.id.your_id);
我认为这个问题是你拿的引用EditText上不属于你的活动布局,要连接监听到错误的观点。
im currently porting a database manager to android and due to performance reasons i like to update only propertys that have been modified. Im trying to do this with the addTextChangedListener in order to add modified entrys to a List, but my Program never enters any of its methods.
EditText Et = (EditText) Editors.get(Prop.Name);
Et.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if(Prop.GetType() == Property.PROPTYPE.num) {
float f = Float.parseFloat(s.toString());
Prop.FromString(f);
}
else {
Prop.FromString(s.toString());
}
propertiesToUpdate.add(Prop);
});
Et.setText(Prop.ToString());
Why are getting the EditText instance this way. It's part of your activity layout so you should get it something like this
EditText Et = (EditText) findViewById(R.id.your_id);
I think the problem is that you're holding a reference to a EditText which don't belong to your Activity layout so you are attaching the listener to the wrong view.
这篇关于安卓的EditText和addTextChangedListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!