添加space_key, enter_key, clear_key, delete_key的处理。
final EditText view = (EditText) mInflater.inflate(R.layout.sms_receipient_input, null);
view.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
String txt = view.getText().toString();
if(event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_SPACE:
case KeyEvent.KEYCODE_ENTER:
if(!TextUtils.isEmpty(txt)) {
mViewGroup.addView(getRecipientItem(null, txt), mViewGroup.getChildCount()-2);
view.setText("");
}
break;
case KeyEvent.KEYCODE_CLEAR:
case KeyEvent.KEYCODE_DEL:
int count = mViewGroup.getChildCount();
if(count>2){
mViewGroup.getChildAt(count-3).performClick();
}
break;
}
}
return false;
}
});