Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
btnclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String options=edtvalue.getText().toString();
                if(options.equals("pass"))
                {
                    tv.setText("you are pass");

                } else if(options.equals("fail"))

                {
                    tv.setText("you are fail");
                }
                else
                {
                    tv.setText("invalid");
                }


What I have tried:

This is a simple if, if else code for pass and fail. if I add value instead of pass and fail for example if marks greater than 300 then pass if less than 300 then fail.
so how code will be write?
Posted
Updated 28-Apr-21 23:43pm

Java
String value=edtvalue.getText(); // it is not necessary to call toString on a method that returns a string.
Integer marks = Integer.parseInt(value); // convert the text to a number
if (marks < 300) // compare the value 
{
    // action if less than 300
}
else
{
    // action if 300 or greater
}
 
Share this answer
 
Java
<pre>btnclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String value=edtvalue.getText().toString();
                Integer marks = Integer.parseInt(value);
                if (marks < 300)
                {
                    tv.setText("you are Fail");

                } else

                {
                    tv.setText("you are Pass");
                }


Thanks you sir for reply. Its working good now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900