If edit text contains spaces then show error [closed] - android

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
EditText text = (EditText)findViewById(R.id.text);
if(condition)
{
}
if edittext containing space bar then show error

There should be no " " space in the EditText is what you want.
Nobody will provide you with a ready working code. Here are some pointers to proceed.
String a = text.getText().toString();");
This will help you get the string in the edittext
So you have the string that the user had entered in the edittexxt.
No you need to use a simple function that will check if a character is present in the string.
String s= String from edittext;
boolean p=s.contains(" ");
if(p)
//call function for error
else
//safe to proceed

Use the following code to show error.
EditText text = (EditText)findViewById(R.id.text);
if(text .getText().toString().contains(" "))
{
text.setError("Field cannot be have space.");
}

Related

Again N Again Split the string with "#" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to split the String with the # symbol
'#Happy#sad#Angry#Tear and so on`
I don't know how many times user enters hashtags so how can I split that String?
I tried this:
allhashtag= String.valueOf(edt_hashtag.getText());
String tag1[] =allhashtag.split("#");
String tag2= tag1[0];
Try for loop for split String when we don't know how many characters in String
Try this code:
String s = allhashtag;
if(s.toString().contains("#"))
{
String tags[]=s.toString().split("#");
for (String tag : tags)
{
Log.e("tag",""+tag);
}
}

search text in a website programmatically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i want my app to search a specific website(from an url) for a specific text and give me the 3 chars after that text or to search for a pattern with a placeholder and give me the first matching string. Is that possible? There is no need to display the website.
Once you download the page using something like HTTPUrlConnection, you can use a regex with your search term
Pattern p = Pattern.compile("specific text(\w\w\w)");
Matcher m = p.matcher(site_text);
boolean b = m.matches();
The three \w will be captured in a group for you to use if there's a match.

How to Count numbers of line, word and characters from Edittext field in Android [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am beginner, I want to make one simple application that will count number of lines, words and characters from whatever we have entered in Editext field. i want result like:
EditText : My name is abc.
Button CLick---->
Result:
No. of Words : 4
No. of Characters : 14
No. of Lines : 1
First get the Edittext value.then do like as java word counter
EditText e1=(EditText) findViewById(R.id.youredittextid);
String mytext=e1.getText().toString();
Apply java code for mytext
lines in edittext can vary depending on device....
for words:
char ch[]= new char[s.length()]; //in string especially we have to mention the () after length
for(i=0;i<s.length();i++)
{
ch[i]= s.charAt(i);
if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) )
c++;
}
and for characters: s.length()

How do I return an int from EditText and than show that number in Toast? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner at programming Android, please help with this simple project.
I want an integer to show up in toast, which I write in textBox. I do not know what to put in the highlighted part here.
Sorry for the link, but I cannot post the picture
You need to use the getText() method to get the text the user entered.
Change the myEdit declaration to:
final EditText myEdit = ... ;
and then use:
Toast.makeText(MainActivity.this, myEdit.getText().toString(), ...

How to get the answers in String Array (ie) Vector? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This is my code:
blanks=new EditText(this);
String values =blanks.getText().toString();
answers.put(relative.getId(),answer);
if(answer[0].equals(values)) {
Toast.makeText(this,"Match!", Toast.LENGTH_LONG).show();
}
Your code makes no sense. You crate a new EditText field, and then immediately get the text. But this will always be null.

Categories

Resources