2

I have not found documentation on how I can get the first letter of a value in a TextView?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
user2847219
  • 555
  • 1
  • 16
  • 27

7 Answers7

7

Very easy,

String strTextview = textView.getText().toString();
strTextView = strTextView.substring(0,1);

Alternatively you can try following way too

char firstCharacter = textView.getText().toString().charAt(0);
Lucifer
  • 29,392
  • 25
  • 90
  • 143
3

To get the first letter you'll have to make this call:

char firstCharacter = myTextView.getText().charAt(0);
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
2

Use the method from below. Provide the string from TextView as the parameter.

public String firstStringer(String s) {
            String str= s.substring(0, Math.min(s.length(), 1));
            return str;
        }
Dhaval
  • 1,597
  • 11
  • 15
2

You can use this

   TextView tv = (TextView) findViewById(R.id.textview);
   String frstLetter = tv.getText().substring(0, 1);
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
EdmDroid
  • 1,350
  • 1
  • 11
  • 25
1

it is simple. To retrieve the Text from the TextView you have to use getText().toString();

String textViewContent = textViewInstance.getText().toString();

and the first letter textViewContent.charAt(0)

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
1

To fetch the content of the string from TextView:

 String content = textView.getText().toString();

To fetch the first character

char first = content.charAt(0);
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
user3388324
  • 572
  • 5
  • 18
1

Try this

 String value = text.getText().toString();
 String firstTen = value.substring(0, 1);
Arun Antoney
  • 4,292
  • 2
  • 20
  • 26