Question

final String a="cout";
    Button okButton = (Button) findViewById(R.id.OK);
    okButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            EditText text = (EditText)findViewById(R.id.Vprasanje1);
            String value = text.getText().toString();
            if(value == a)
            {
                EditText banana = (EditText) findViewById(R.id.Vprasanje1);
                banana.setTextColor(Color.GREEN);
            }

This is the code I've come up with, I just started programing in Java and have no clue what to do atm.

Was it helpful?

Solution

Try this code :
Compare String using .equals or .equalsIgnoreCase method.

final String a="cout";
    Button okButton = (Button) findViewById(R.id.OK);
    okButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            EditText text = (EditText)findViewById(R.id.Vprasanje1);
            String value = text.getText().toString();
            if(value.equals(a))
            {
                EditText banana = (EditText) findViewById(R.id.Vprasanje1);
                banana.setTextColor(Color.GREEN);
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top