안드로이드 라디오버튼
2013. 6. 7. 14:45ㆍMobile/Android
반응형
package com.example.ggari_radiogroup;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity implements OnCheckedChangeListener{
RadioGroup radioGroup;
RadioButton rb1;
RadioButton rb2;
RadioButton rb3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup = (RadioGroup)findViewById(R.id.radioGroup);
rb1 = (RadioButton)findViewById(R.id.rb1);
rb2 = (RadioButton)findViewById(R.id.rb2);
rb3 = (RadioButton)findViewById(R.id.rb3);
radioGroup.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (radioGroup.getCheckedRadioButtonId() == R.id.rb1) {
Toast.makeText(getApplicationContext(), "까리가 선택됨", 1).show();
} else if (radioGroup.getCheckedRadioButtonId() == R.id.rb2) {
Toast.makeText(getApplicationContext(), "리그오브레전드가 선택됨", 1).show();
} else {
Toast.makeText(getApplicationContext(), " league of legends", 1).show();
}
}
}
main.xml
반응형
'Mobile > Android' 카테고리의 다른 글
| android studio 한글 (2) | 2013.06.27 |
|---|---|
| 안드로이드 TextView (0) | 2013.06.12 |
| Unable to execute dex: Multiple dex files define Lrsearch/connector/CalcBase; (0) | 2013.06.04 |
| 안드로이드 SVN (0) | 2013.05.30 |
| 안드로이드 다이얼로그 (0) | 2013.05.30 |