Why does my onCheckedChanged method not get fired when i click a different radio button in my radio group?

StackOverflow https://stackoverflow.com//questions/9658132

문제

package matthew.datacollector;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.os.Bundle;

public class DataCollectorActivity extends Activity implements RadioGroup.OnCheckedChangeListener, View.OnClickListener {

    private TextView tv;
    private RadioGroup rg;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.tv = (TextView) findViewById(R.id.textView1);
        this.rg = (RadioGroup) findViewById(R.id.radioGroup1);
        rg.setOnClickListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        this.tv.setText("lol");
        Toast.makeText(this.getApplicationContext(), "hey", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onClick(View v) {
        this.tv.setText("lol");
    }
}

I don't understand why this isn't working : /. I want it to set the text of the textview, and you can even see I have thrown in a toast for debugging. Still nothing, I've tried it without the @Overrides too

도움이 되었습니까?

해결책

You forgot to set the listener onCheckedChange on the RadioGroup:

rg.setOnCheckedChangeListener(this);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top