tags:

views:

87

answers:

1

Does this exist? I need to make a TextView which is always uppercase.

A: 

I don't see anything like this in the TextView attributes, however you could just make the text uppercase before setting it:

textView.setText(text.toUpperCase());

If the TextView is an EditText and you want whatever the user types to be uppercase you could implement a TextWatcher and use the EditText addTextChangedListener to add it, an on the onTextChange method take the user input and replace it with the same text in uppercase.

editText.addTextChangedListener(upperCaseTextWatcher);

final TextWatcher upperCaseTextWatcher = new TextWatcher() {

public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}

public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    editText.setText(editText.getText().toString().toUpperCase());
    editText.setSelection(editText.getText().toString().length());
}

public void afterTextChanged(Editable editable) {
}

};

lander16
That works if `text` is a String. If you're getting the String from your xml files using `R.string.someID`, then you'll need to throw in a `Resources.getString` call (http://developer.android.com/reference/android/content/res/Resources.html#getString%28int%29)
MatrixFrog
I was afraid I'd have to do it this way. Was hoping there'd be a simple attribute I was missing.
Joren