{"id":19674,"date":"2022-11-07T10:28:32","date_gmt":"2022-11-07T04:58:32","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/"},"modified":"2022-11-07T10:28:32","modified_gmt":"2022-11-07T04:58:32","slug":"solved-edit-text-first-time-to-input-a-letter-validation","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/","title":{"rendered":"[Solved] Edit text first time to input a letter validation"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-29618868\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"29618868\" data-parentid=\"29618731\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You, my friend, need a <\/p>\n<pre><code>EditText editText = (EditText)findViewById(R.id.edittext);\neditText .addTextChangedListener(new TextWatcher() {\n\n        @Override\n        public void afterTextChanged(Editable s) {\n            ; \/\/Do nothing\n        }\n\n        @Override\n        public void beforeTextChanged(CharSequence s, int start, int count, int after) {\n            ; \/\/Do nothing\n        }\n\n        @Override\n        public void onTextChanged(CharSequence s, int start, int before, int count) {\n            \/\/TODO put your code here.\n        } \n\n    });\n<\/code><\/pre>\n<p>Now, just check to see if that &#8220;s&#8221; Char Sequence contains your letter and you&#8217;ll be on your way.<\/p>\n<hr>\n<p>Edit:<br \/>\nOnce you have that CharSequence, just check to see that the first char is a letter.<\/p>\n<p>To get the first char, do <\/p>\n<pre><code>s.charAt(0);  \/\/Note: if there is nothing here, it could throw a null pointer.\n<\/code><\/pre>\n<p>The Character class has a static function that you can use to see if it is a letter (or a number, capital, lowercase, digit, digit or letter, etc) called <\/p>\n<pre><code>Character.isLetter(char); \n<\/code><\/pre>\n<p>so you could do something like <\/p>\n<pre><code>        public void onTextChanged(CharSequence s, int start, int before, int count) {\n            \/\/Check to see that there is at least 1 char to look at.\n            \/\/Then check to see if it is a letter.\n            \/\/(Note: the &amp;&amp; is AND, so both things have to be true)\n            if (s.length() &gt; 0 &amp;&amp; Character.isLetter(s.charAt(0))) {\n                ; \/\/Display your button\n            } else { \n                ; \/\/Display your error\n            }\n        }\n<\/code><\/pre>\n<p>Does that help?<\/p>\n<hr>\n<p>You can create a new class called MyTextWatcher (either in it&#8217;s own file where you can import it anywhere or as a class within a class (if all of the edit texts are in the same area)), and then inside there do the regular stuff you are now expert at:<\/p>\n<pre><code>public class MyTextWatcher implements TextWatcher {\n    @Override\n    public void beforeTextChanged(CharSequence s, int start, int count, int after) {\n    }\n    @Override\n    public void onTextChanged(CharSequence s, int start, int before, int count) {\n    }\n    @Override\n    public void afterTextChanged(Editable s) {  \n    }\n}\n<\/code><\/pre>\n<p>I personally prefer doing it inside the class that contains the edittext, but it can go in a separate file (that you import) and then it&#8217;s more reusable.  And if for any reason, you need to access things with your TextWatcher, you can pass them in as a constructor.  The advantage of doing things inside the class is that you don&#8217;t have to pass things into a constructor.  It&#8217;s just less things for you to do.  But here is an example of that constructor&#8230;<\/p>\n<pre><code>public class MyTextWatcher implements TextWatcher {\n    private Thing1 mThing1;\n    private Thing2 mThing2;\n    public MyTextWatcher(Thing1 t1, Thing2 t2) {\n        mThing1 = t1;\n        mThing2 = t2;\n    }\n    ...\n}\n<\/code><\/pre>\n<p>Note: Just be careful not to interlink things too much when doing that.  It can get hairy later on. \ud83d\ude42<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">3<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Edit text first time to input a letter validation <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You, my friend, need a EditText editText = (EditText)findViewById(R.id.edittext); editText .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { ; \/\/Do nothing } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { ; \/\/Do nothing } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { \/\/TODO put your &#8230; <a title=\"[Solved] Edit text first time to input a letter validation\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\" aria-label=\"More on [Solved] Edit text first time to input a letter validation\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[452,1250,954,475],"class_list":["post-19674","post","type-post","status-publish","format-standard","hentry","category-solved","tag-android","tag-android-edittext","tag-button","tag-validation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Edit text first time to input a letter validation - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Edit text first time to input a letter validation - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You, my friend, need a EditText editText = (EditText)findViewById(R.id.edittext); editText .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { ; \/\/Do nothing } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { ; \/\/Do nothing } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { \/\/TODO put your ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-07T04:58:32+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Edit text first time to input a letter validation\",\"datePublished\":\"2022-11-07T04:58:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\"},\"wordCount\":265,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"android\",\"android-edittext\",\"button\",\"validation\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\",\"name\":\"[Solved] Edit text first time to input a letter validation - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-07T04:58:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Edit text first time to input a letter validation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Edit text first time to input a letter validation - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Edit text first time to input a letter validation - JassWeb","og_description":"[ad_1] You, my friend, need a EditText editText = (EditText)findViewById(R.id.edittext); editText .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { ; \/\/Do nothing } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { ; \/\/Do nothing } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { \/\/TODO put your ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/","og_site_name":"JassWeb","article_published_time":"2022-11-07T04:58:32+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Edit text first time to input a letter validation","datePublished":"2022-11-07T04:58:32+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/"},"wordCount":265,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["android","android-edittext","button","validation"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/","url":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/","name":"[Solved] Edit text first time to input a letter validation - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-07T04:58:32+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-edit-text-first-time-to-input-a-letter-validation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Edit text first time to input a letter validation"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/19674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=19674"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/19674\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=19674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=19674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=19674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}