-4

I want to set an editable text field to display the first letter of a string and I cannot figure out how. I have tried the following way and don't get any errors but it doesn't work. I want to make is the first letter of a string within an array of strings and I can recall the correct string index but not the first letter of that particular string.

 String s = "Example" ;
 char letter = s.charAt (0);
 editText.setText (letter);

Thanks

  • ^ No this is nothing like that question. ^ – Timinycricket Feb 08 '17 at 00:21
  • 1
    So you obviously didn't even try to think about the answers there? Very sad. – Tom Feb 08 '17 at 00:24
  • Are you talking about the StringValueOf () method? I could set the text to just a single letter no problem but I am trying to get a certain index of a string.. is that how I can do it? Am I correct to use the charAt() method as a char to put into the edit text? – Timinycricket Feb 08 '17 at 00:32
  • I do not know what I am doing as I am obviously a beginner at programming – Timinycricket Feb 08 '17 at 00:33
  • It is fine that you are a beginner. Just that you have complained that the marked duplicate is not your solution, but yet the answer you accepted here is the exact same as the top-voted answer there. The root issue is not so much "set EditText text to a character (in Android)", it is "how to get a `char` to a `String` *in Java*". In other words, it helps if you know Java before doing Android. – OneCricketeer Feb 08 '17 at 23:44
  • Thank you cricket_007 I am trying. And actually I found out that what I really was wanting to know was how to use a substring. But now I know how to do both! – Timinycricket Feb 10 '17 at 00:53

1 Answers1

-1

you can't setText a char, you have to setText either a String ort a CharSequence.

I suggest edit.setText(String.valueOf(letter))

SteelBytes
  • 6,905
  • 1
  • 26
  • 28
  • 1
    Can you vote as a duplicate, please? – OneCricketeer Feb 08 '17 at 00:30
  • Thank you! all I wanted was a simple answer not an adventure through other questions – Timinycricket Feb 08 '17 at 00:35
  • @Timinycricket You mean you tried your best to avoid research? Quite unusual for someone who claims that he teaches himself. – Tom Feb 08 '17 at 00:38
  • I am not at my computer where I can test and compare the other post's answers and I didn't want my question to be ignored because I have more to my question than that but thank you anyway. I didn't know there were such Jenks on here sheesh. – Timinycricket Feb 08 '17 at 00:44