안드로이드 개발 질문/답변
(글 수 45,052)
체크박스를 클릭할때 마다 text내용과 이미지가 바뀌게 나오게 하는 내용인데요.
텍스트는 됬는데.. 이미지 체인지를 모르겠습니다.
2개의 사진이 첨부되어있습니다.
보시면 아시겠지만 언체크와 체크 상태에서 문구는 바뀝니다.
하지만 이미지 유니콘 사진은 바뀌지 않습니다.
체크를 했을때 바꾸고 싶습니다.
자바파일입니다.
package com.kit.fanta.fanta;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
public class FantaActivity extends Activity implements OnCheckedChangeListener {
/** Called when the activity is first created. */
CheckBox cb;
EditText edit1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb = (CheckBox)findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
edit1 = (EditText)findViewById(R.id.edit);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked)
{
edit1.setText("20090888_LGH Chceck On!");
}
else
{
edit1.setText("Not Clicked! 20090888_LGH");
}
}
}
xml파일입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="http://www.kumoh.ac.kr"
android:lines="1"
android:autoLink="web"
/>
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="center"
/>
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/lgh"
/>
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unchecked"
/>
</LinearLayout>




텍스트 변경하는 부분에서.. edit의 텍스트를 변경하고 있지요?
그러면 같은 부분에서 imageButton의 이미지를 변경하면 되지 않나요?
edit1.setText("20090888_LGH Chceck On!");
이 부분 바로 아래에
button.setImageResource(R.drawable.ic_launcher);
뭐 이런식으로.. 해주면 되지 않겠어요?
R.drawable.ic_launcher는 원하는 이미지 리소스로 해야겠죠;