jene barve
jene barve

Reputation: 33

No output in EditText. Why?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View view) {
            CheckBox yes = (CheckBox) findViewById(R.id.yes);
            CheckBox no = (CheckBox) findViewById(R.id.no);
            EditText ageText = (EditText) findViewById(R.id.ageText);
            EditText editText = (EditText) findViewById(R.id.editText);
            EditText editText3 = (EditText) findViewById(R.id.editText3);
            int age;
            age = 0;

            if (yes.isChecked()) {
                editText3.setText(age + 15);
            } else if (no.isChecked()) {
                editText3.setText(age - 10);
            }
            finish();
        }
    });
}

This code is not giving me any output in editText3. Why this is happening? The code has no bugs but still no output!

Upvotes: 0

Views: 101

Answers (2)

Sasi Kumar
Sasi Kumar

Reputation: 13288

You wrongly used setOnClickListener. Change your code this way:

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        boolean checked = ((CheckBox) view).isChecked();
        if (checkBox.isChecked()) {
            //check age is string or not.if not a string means change into String format
            editText3.setText(age + 15);
        } else if (checkBox.isChecked()) {
            editText3.setText(age - 10);
        }
    }
});

Upvotes: 1

Mohammed Aouf Zouag
Mohammed Aouf Zouag

Reputation: 17132

Change

button.setOnClickListener(new)onClickListener() ...

to

button.setOnClickListener(new View.OnClickListener() { 
    @Override
    public void onClick(View v) {
        boolean checked = ((CheckBox) view).isChecked();

        if (checkBox.isChecked()){
            editText3.setText(age+15);
        } else if (checkBox.isChecked()){
            editText3.setText(age - 10);
        }
    }
});

Upvotes: 2

Related Questions