我只是想在用户编辑EditText时显示Toast消息,但我没有收到Toast消息!
我做错了什么?
public class OfferRide extends Activity implements TextView.OnEditorActionListener {
private EditText et_msg;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
initializeViews();
}
private void initializeViews() {
et_msg = (EditText) findViewById(R.id.et_msg);
et_msg.setOnEditorActionListener(this);
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Toast.makeText(getApplicationContext(), "Editing",Toast.LENGTH_LONG).show();
return false;
}
}
答案 0 :(得分:2)
onEditorAction()
中按Enter键, EditText
将有效。要在每次进行更改时触发操作,都可以使用TextWatcher()
et_msg.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Toast.makeText(getApplicationContext(), charSequence ,Toast.LENGTH_LONG).show();
}
@Override
public void afterTextChanged(Editable editable) {}
});