어느 예제를 봐도 라디오버튼을 체크하고 버튼을 눌러야 실행되는 거더라구요
근데 버튼없이 라디오 버튼을 체크만해도 이미지가 바뀔 수 있도록 하는 건 어떻게 하나요?
소스 드릴게요~
먼저 main.xml
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</EditText>
<Button
android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="글자 나타내기" >
</Button>
<Button
android:id="@+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="홈페이지 열기" >
</Button>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="진저브래드" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이스크림 샌드위치" />
</RadioGroup>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
자바는
package com.cookandroid.chapter2_8;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Chapter2_8Aticity extends Activity {
Button btn1, btn2;
RadioButton radio1, radio2;
EditText edit;
RadioGroup radioGroup1;
ImageView imageView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
radio1 = (RadioButton) findViewById(R.id.radio1);
radio2 = (RadioButton) findViewById(R.id.radio2);
edit = (EditText) findViewById(R.id.edit);
imageView1 = (ImageView) findViewById(R.id.imageView1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "http://m.naver.com", 0)
.show();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://m.naver.com"));
startActivity(mIntent);
}
});
radioGroup1.getCheckedRadioButtonId(){
public void onClick(View arg0) {
switch (radioGroup1.getCheckedRadioButtonId()) {
case R.id.radio1:
imageView1.setImageResource(R.drawable.a);
break;
case R.id.radio2:
imageView1.setImageResource(R.drawable.b);
break;
}
}
맨마지막 부분에서 위에서 첫번째랑 두번째로 어떻게 해야되는지.. 가르쳐주세요ㅜ.ㅜ
}}
}