2016-04-02 8 views
1
editText.addTextChangedListener(new TextWatcher() { 
    public void afterTextChanged(Editable s) { 
    //SecondAt.mBluetoothIO.sendMessage("back"); 
    } 

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

    // SecondAt.mBluetoothIO.sendMessage("back"); 
    } 

    public void onTextChanged(CharSequence s, int start, int before, int count) { 

     if (s.toString().length() == 1) { 
      SecondAt.mBluetoothIO.sendMessage("back"); 
      Toast toast1 = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT); 
      toast1.show(); 
      } 
     else 
      { 
      //****----"here i need to clear the CharSequence s" ----***** 
      } 
    }}); 

私はCharSequenceをクリアする必要があるので、キーボードから各鍵を読み取ってブルートゥースキーボードを作ることができます。 誰か助けてください。アンドロイドのCharSequcenceの明確な要素は?

答えて

1

編集1 EditText

editText.setText(""); 

をクリアすることで試すことができます:あなただけCharSequenceの値をクリアしたい場合は

s = ""; 

しかし、これは、しませんでしょうEditTextのテキストを変更します。したがって、次のコールバックがonTextChangedリスナーの場合、前の値がそこにあります。そのため、EditTextを空にしてCharSequenceに設定してリセットしてください。

編集2:

if (s.toString().length() == 1) { // You are reading the value here. 
     SecondAt.mBluetoothIO.sendMessage("back"); 
     Toast toast1 = Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT); 
     toast1.show(); 
} 
else{ // and deleting it from the edittext here. 
    s = ""; 
    editText.setText(s); 
} 
+0

卿私は、更新の答えを見て、CharSequnceの –

+0

@VishnuViswanathanをクリアする必要があります。ところで、なぜそれは大変でしたか?あなたは何かを達成しようとしていますか? –

+0

私は実際にソフトキーボードの各キーを読み取って、PC用のBluetoothキーボードを作成したいと思います。私を助けてくれますか? –

0

使用:

editText.setText(s.subSequence(start,before-1));