2

I have a list item. Each item extends Textview to create my customized item. In this class I override the setText(CharSequence text, BufferType type) method to do processing on text before I call super.setText(Charsequence text, BufferType type).
But when I call text.toString() method it returns an empty string.

Do you have the same problem or have any tips? Of course I use Unicode text - for example : \u0661\u6662\u663. The list view doesn't have problems showing Unicode dates.

This is my override and process method:

@Override
public void setText(CharSequence text, BufferType type) {
    // TODO Auto-generated method stub
    process(text.toString());
    super.setText(text, type);
}



private void process(String guess) {
    StringBuffer correct = new StringBuffer(GameForm.getCorrectNumber());
    int s = guess.length(); 
    if (s!=correct.length())
        throw new InputMismatchException("Lenght of correct and guess number is different");
    acceptCount = 0;
    warningCount = 0;
    for (int i = 0; i < s; i++) {
        if (guess.charAt(i) == correct.charAt(i)) {
            acceptCount++;
        } else if (correct.indexOf(guess.charAt(i) + "") != -1) {
            warningCount++;
        }
    }
}

s in process(String text) is empty!

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Rasoul Taheri
  • 802
  • 3
  • 16
  • 32

1 Answers1

1

as I already told, use a debugger and put a breakpoint on process(text.toString()); and see what the value of text is. toString() method returns the string representation of CharSequence so if it returns empty string it means that you are passing an empty string to your setText() method.

As String objects are immutable you set your view the same text that you pass to your setText(). Once more -- high time to use a debugger.

Taras Leskiv
  • 1,835
  • 15
  • 33