Capitalize the first letter in EditText

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Capitalize the first letter in EditText

Postby joby.nk » Tue Dec 15, 2009 11:41 am

Hi,

I want to show the first letter capital in an EditText ,i set the setInputType() property, but when i typing small letter is coming my code is pasted below. Anyone can tell me a solution


EditText edtxtGolfrsNm=(EditText)findViewById(R.id.edtxGlfrsName);
edtxtGolfrsNm.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
joby.nk
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 29, 2009 1:22 pm
Location: INDIA

Top

Postby Johan Degraeve » Tue Dec 15, 2009 12:00 pm

I suggest you add a TextChangedListener to your EditText

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         yourTextView.addTextChangedListener(new TextWatcher() {
  2.  
  3.  
  4.  
  5.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  6.  
  7.                 ;
  8.  
  9.             }
  10.  
  11.  
  12.  
  13.             public void onTextChanged(CharSequence s, int start, int before, int count) {
  14.  
  15.                 //check if s[0] is a small letter and if yes do a setText with a new String where
  16.  
  17.                 //the first character is s[0] capitalized
  18.  
  19.             }
  20.  
  21.  
  22.  
  23.             public void afterTextChanged(Editable s) {
  24.  
  25.                 ;
  26.  
  27.  
  28.  
  29.             }
  30.  
  31.         });
  32.  
  33.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
regards,

Johan
Johan Degraeve
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Oct 27, 2009 1:50 pm
Location: Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests