개발도구/aOS - 안드로이드 개발
[안드로이드] 블록형식의 메뉴에서 이미지 선택후 선택한 이미지 활성화
Hay's App
2011. 9. 21. 09:14
기본 main.xml 은 아래와 같이 off 로 초기화 해놓는다.
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageButton android:scaleType="center" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="@drawable/navi_mynews_off"
android:id="@+id/ImgButton5" ></ImageButton>
<ImageButton android:scaleType="center" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="@drawable/navi_stockalarm_off"
android:id="@+id/ImgButton6" ></ImageButton>
<ImageButton android:scaleType="center" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="@drawable/navi_mttw_off"
android:id="@+id/ImgButton7" ></ImageButton>
<ImageButton android:scaleType="center" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="@drawable/navi_comic_off"
android:id="@+id/ImgButton8" ></ImageButton>
</LinearLayout>
class 에서는 버튼의 선택후 setimage(); 로 넘어가기 한다.
public static String ImageButtonType="b1" ;
public void setImage(){
if("b5".equals(ImageButtonType)){
class 에서는 버튼의 선택후 setimage(); 로 넘어가기 한다.
public static String ImageButtonType="b1" ;
ImageButton6 = (ImageButton)findViewById(R.id.ImgButton6);
ImageButton6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageButtonType = "b6";
setImage();
}
}); public void setImage(){
ImageButton5.setBackgroundResource(R.drawable.navi_mynews_off);
ImageButton6.setBackgroundResource(R.drawable.navi_stockalarm_off);
ImageButton7.setBackgroundResource(R.drawable.navi_mttw_off);
ImageButton8.setBackgroundResource(R.drawable.navi_comic_off);
if("b5".equals(ImageButtonType)){
ImageButton5.setBackgroundResource(R.drawable.navi_stockalarm_on);
}else if("b6".equals(ImageButtonType)){
ImageButton6.setBackgroundResource(R.drawable.navi_stockalarm_on);
}else if("b7".equals(ImageButtonType)){
ImageButton7.setBackgroundResource(R.drawable.navi_mttw_on);
}else if("b8".equals(ImageButtonType)){
ImageButton8.setBackgroundResource(R.drawable.navi_comic_on);
}
Log.v("click", ImageButtonType);