2

I have the following code in which I am trying to capitalize the first letter of the string. The code is as follows:

final Button headerButton =  (Button) View.inflate(EikonApplication.getAppContext(), R.layout.manage_markets_category_header_button, null);
headerButton.setOnClickListener(this);                      
headerButton.setText(header.getCategoryTitle().toLowerCase());
linearLayout.addView(headerButton);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • This is basically a duplicate of http://stackoverflow.com/questions/5725892/how-to-capitalize-the-first-letter-of-word-in-a-string-using-java but Stack is complaining that marking it as such would make a circular duplicate list. – J David Smith Jul 01 '13 at 16:45

5 Answers5

1

Use

String title = header.getCategoryTitle().toSubString(0,1).toUperCase);
title += header.getCategoryTitle().toSubString(1).toLowerCase);

headerButton.setText(title);
duggu
  • 37,851
  • 12
  • 116
  • 113
Bharat Jyoti
  • 394
  • 2
  • 6
0

Here is a great answer. Note that this is actually a java question, not merely android.

Community
  • 1
  • 1
J David Smith
  • 4,780
  • 1
  • 19
  • 24
0

Set android:inputType="textCapSentences" on your EditText.

http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

Patrick
  • 33,984
  • 10
  • 106
  • 126
  • I am not using edittext, just the code above. I tried headerButton.setText(header.getCategoryTitle().toUpperCase().charAt(0)); didn't work. –  Jul 01 '13 at 18:02
0
WordUtils.capitalize("i am fine") = "I Am Fine"

Not sure android support wordutils or not , if it support then its easy to use .

Rahul
  • 10,457
  • 4
  • 35
  • 55
0
public String capitalizeFirstLetterAndLowerCaseTheRest(String original) {
        if (original == null || original.length() == 0) {
            return original;
        }
        return original.substring(0, 1).toUpperCase() + original.substring(1).toLowerCase();
    }

Loop on it if you want to do it on every word.

Source : How to capitalize the first letter of word in a string using java?

Community
  • 1
  • 1
hermance
  • 73
  • 3
  • 12