2015-02-09 105 views
1

我的应用程序我可以在某个时间“x”EditText字段。我添加dinamicaly新的EditText,因此它们的数量可能会有所不同。我想为我的所有EditText有一个侦听器,它可以告诉哪些视图(edittext)已被更改。多个EditText具有相同的setOnEditorActionListener

我搜索了一下,发现:

private TextWatcher textWatcher = new TextWatcher() 

,但这样做的问题是,它没有一个参数视图V告诉我什么看法正在发生变化,如:

OnFocusChangeListener listener = new OnFocusChangeListener() .....public void onFocusChange(final View v, .... 

同时还发现:

OnEditorActionListener 

具有:

public boolean onEditorAction(TextView v, (parammeter) 

但是,当用户输入时,在输入完成后它不会触发...

是否有可用于所有我的EditText(无母校他们的人数)的监听器和具有视图V parammeter ?

对不起,我的英语...

任何帮助将是很好的

回答

1

OnEditorAction是侦听完成,完成键盘按键动作的适当方式。

尝试使用此方法:

@Override 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
{ 
    if (actionId == EditorInfo.IME_ACTION_DONE) 
    return(true); 
} 

哪里PARAMS是:

v   The view that was clicked. 
actionId Identifier of the action. This will be either the identifier you supplied, or EditorInfo.IME_NULL if being called due to the enter key being pressed. 
event  If triggered by an enter key, this is the event; otherwise, this is null. 
0

我找到了符合我更好的解决方案:

我创建了一个类:

public class Whowho implements TextWatcher 
{ 
    private View view; 
    private Activity act; 
    public Whowho(EditText view, Activity activ) 
    { 
     this.view = view; 
     this.act=activ; 
    } 
    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count,int after) {} 
    @Override 
    public void onTextChanged(CharSequence s, int start, int before, int count) {} 
    @Override 
    public void afterTextChanged(Editable s) 
    { 
     EditText ed = (EditText) act.findViewById(view.getId()); 
     .... 
     AsyncHttpClient client = new AsyncHttpClient(); 
     RequestParams params = new RequestParams(); 
     ..... 
     ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(R.drawable.ok, 0, 0, 0); 
     ((TextView) view).setText(...); 

} }

我用这样的:

ed.addTextChangedListener(new Whowho(ed,CLASS.this)); 

对我来说,工作的伟大。希望它能帮助别人

相关问题