2012-07-11 71 views
0

我正在开发一个android应用程序..我想根据用户从softkeyboard输入的键在editText中设置文本。android change setText

如何在android应用程序的EditText中设置文本内容之前更改文本内容???

回答

2

With TextView.setOnEditorActionListener()在EditText中执行操作时可以通知您。

+0

是EDITTEXT,我想改变文本之前它被设置 – 2012-07-11 13:29:33

+0

我不想使用et.setText – 2012-07-11 13:29:59

1

这可能对你有所帮助。

editText.addTextChangedListener(new TextWatcher() { 
    public void onTextChanged(CharSequence s, int start, int before, int count) { 
    } 

    public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    } 

    public void afterTextChanged(Editable s) { 
    } 
}); 
+0

我试过,但没有奏效 ,因为使用的setText会造成问题,我 – 2012-07-11 13:30:27

+0

我想在不使用et.setText的情况下更改文本 – 2012-07-11 13:30:48

+0

这可让您在设置文本后对其进行修改,这样我就不明白问题所在。你应该使用beforeTextChanged,这样你就可以理解什么是改变,如果这很重要,并且完成afterTextChanged。如果你不能使用setText(),那么我觉得你有一个更深的问题,并且可能做的不够理想。 http://developer.android.com/reference/android/text/TextWatcher.html – 2012-07-11 17:23:24