안녕하세요 금광입니다.

어지간하면 혼자 해결해 보려고 했는데... 시간이 너무 걸려서 도움을 구해봅니다.

selector 관련 elements를 하나씩 테스트 하던 중에 발생한 문젠데요

AVD에 올리면 첫번째 imagebutton에 focus가 생겨 있습니다. ( 아래 그림 참조하세요)

 

그런데 this.getCurrentFocus();를 이용하여 로그를 찍어보니 아래와 같이 null로 나옵니다.

행여나해서 imagebutton의 foucs 상태를 isFocused() 메서드로 알아보니 둘다 focus가 아니라고 false로 나오네요

(아래 그림 참조하세요)

 

재밌는건 첫번째 올릴때만 그렇고 imagebutton을 한번 클릭하면 focus가 사라집니다.

그래서 그런지 아무리 nextfocusdown, nextfocusup 엘리멘트를 사용하여도 focus가 변경되질 않네요

 

focus에 대해 개인적으로 자료를 모아보고 있는데, 저와 같은 경우를 못찾고 있습니다.

혹시라고 같은 문제를 해결해 보셨다면, 도움 부탁드립니다.

 

아래는 참고 소스 입니다. imagebutton에서 사용한 png 파일 3개는 첨부하였습니다.

 

끝까지 읽어주셔서 감사합니다.

 

--------------------------------- 소스 관련 --------------------------------------

 

 

 

---------------- selector_tom.java---------------

package kr.co.tom.selector;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageButton;

public class selector_tom extends Activity
{
 private ImageButton ImageButton_selector = null;
 private ImageButton ImageButton_selector2 = null;
 
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  ImageButton_selector = (ImageButton)findViewById(R.id.ImageButton_selector);
  ImageButton_selector2 = (ImageButton)findViewById(R.id.ImageButton_selector2);

  Log.e("tom", "getCurrentFocus = "+ this.getCurrentFocus());
  Log.e("tom", "000, 1 =  "+ImageButton_selector.isFocused()+", 2 = "+ImageButton_selector2.isFocused()+", focus = ");
 }
}

---------------- main.xml---------------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 android:orientation="vertical">
 <ImageButton
  android:id="@+id/ImageButton_selector"
  android:src="@drawable/selector_test"
  android:nextFocusDown="@+id/ImageButton_selector2"
  android:layout_height="20dp"
  android:layout_width="20dp"/>
 <ImageButton
  android:id="@+id/ImageButton_selector2"
  android:src="@drawable/selector_test"
  android:nextFocusUp="@+id/ImageButton_selector"
  android:layout_height="20dp"
  android:layout_width="20dp"/>
</LinearLayout>

---------------- selector_test.xml ---------------

<selector
 xmlns:android="http://schemas.android.com/apk/res/android">
  <item
  android:drawable="@drawable/press"
  android:state_pressed="true"
  android:layout_height="20dp"
  android:layout_width="20dp"
  />
 <item
  android:drawable="@drawable/focus"
  android:state_pressed="false"
  android:state_focused="true"
  android:layout_height="20dp"
  android:layout_width="20dp"
  />
 <item
  android:drawable="@drawable/notpress"
  android:layout_height="20dp"
  android:layout_width="20dp"
  />
</selector>