で
おかげで、このように試してみてください、私はあなたを提供することができ、最も簡単な解決策はString.replace()
を使用することです、このコード
boolean userPressedKey = false ;
int spaceCount = 0;
yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
userPressedKey = false ;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
userPressedKey = true;
});
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (userPressedKey) {
if (keyCode == KeyEvent.KEYCODE_SPACE) {
spaceCount ++;
if(spaceCount == 2){
//append comma to the edittext here
Toast.makeText(MainActivity.this, "White space is clicked twice", Toast.LENGTH_LONG).show();
}
return true;
}else{
spaceCount=0;
}
}
super.onKeyDown(keyCode, event);
}
私はこのために、この.provide溶液中のテキストを設定することはできませんので、私はmultiautocompletetextviewを使用しています。 – dipali
あなたはそれを行うことができます、私はこのコードを行い、 'MultiAutoCompleteTextView'とそれを使用して完全に動作しています。[docs](https://developer.android.com/reference/android/widget/MultiAutoCompleteTextView.html) 'MultiAutoCompleteTextView'も' EditText'を拡張しているので、 'EditText'のすべてのプロパティを使うことができます。 –
大歓迎:) –