-2

so umm my if else is buggy it only shows the else option and not the if(data == "heavy") i just want that is type is equal to heavy and not light then one of the linearlayout vanishes goes invisible and the other way around... help me please...

heres my code:

    Intent intentType = getIntent();
    String valueType = intentType.getStringExtra("type");
    EditText displayType = (EditText) findViewById(R.id.editTextType1);
    displayType.setText(valueType);

    LinearLayout one = (LinearLayout) findViewById(R.id.type1);
    LinearLayout two = (LinearLayout) findViewById(R.id.type2);


    String data = displayType.getText().toString();
    if(data == "heavy") {
        one.setVisibility(View.VISIBLE);
        two.setVisibility(View.INVISIBLE);
    } else {
        one.setVisibility(View.INVISIBLE);
        two.setVisibility(View.VISIBLE);
    }

the codes from previous .java file:

    EditText units = (EditText) findViewById(R.id.editTextUnits);
    units.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(new Intent(MainActivity.this, MainActivity3.class));
            Intent intentType = getIntent();
            String valueType = intentType.getStringExtra("type");
            intent.putExtra("type", valueType);
            startActivity(intent);
        }
    });

the other .java file

 private void SetOnClickWeightButton(){
        Button btn = (Button) findViewById(R.id.buttonWeight);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity2.this, MainActivity.class);
                intent.putExtra("type", "heavy");
                startActivity(intent);
            }
        });
    }
private void SetOnClickLengthtButton(){

    Button btn = (Button) findViewById(R.id.buttonLength);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity2.this, MainActivity.class);
            intent.putExtra("type", "light");
            startActivity(intent);
        }
    });
}
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
George Go
  • 13
  • 7
  • take a look here : http://stackoverflow.com/questions/7520432/java-vs-equals-confusion – giorashc Jan 06 '15 at 08:44
  • When you found the solution to your problem you should accept an answer that describes how you made it instead of fixing the error in your question. (This is how this site works.) – moooeeeep Jan 13 '15 at 09:11

1 Answers1

0

Use String.equals for comparing String variables value instead of ==

Community
  • 1
  • 1
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213