basically its a wordle type game where we take input and if the first letter of the input is the same as the first letter of our word "sc" it should make the textView background color to green or yellow if not in the right position
String str=editText.getText().toString();
String first=str.substring(0,1);
String sec=str.substring(1,2);
String third=str.substring(2,3);
String fourth=str.substring(3,4);
if(count==0)
{
textView1.setText(first);
textView2.setText(sec);
textView3.setText(third);
textView4.setText(fourth);
if(first==sc.substring(0,1))
{
textView1.setBackgroundColor(Color.GREEN);
}
else if(first==sc.substring(1,2)|| first==sc.substring(2,3) || first==sc.substring(3,4))
{
textView1.setBackgroundColor(Color.YELLOW);
}
i have tried this but it doesn’t seem to be working it does no change
i am new to android studio code so please excuse if this has a very easy solution and i have also tried searching for similar questions online but none of them seemed to be working
2
Answers
In your code, you try for execute your if statement inside if(count==0). I assume you try execute your code if wordle is not fill yet since you dont explain clearly about count.
Based on your question here my answer, first you need initialize input and sc value
Second, use if statement for check first letter is already filled
Inside first if, create if statement for compare first letter with sc value
This simple way for reach your goal
==
use when we have to compare integers. But you are using==
to compare strings. Which is wrong. For comparingStrings
you have to usestring.matches()
orstring.equals()
.Make changes in your code as below
Let me know if the problem has not been solved yet.