버튼 네개 가운데 원하는 버튼 하나를 누르고 있으면 나머지 버튼 세개의 이미지에 변화를 주려고 하였고 이미지뷰를 TouchListener를 이용해서 버튼처럼 만들었습니다.
그런데 이미지를 누른 상태에서 드래그하여 이미지 밖으로 벗어나서 손을 떼면 버튼 선택이 안되도록 하고 싶은데
터치가 이미지 밖으로 나가는걸 어떻게 감지하는지 모르겠습니다.
원래는 이미지 버튼을 이용해서 만들어보려고 하였으나 버튼이 눌러진 상태인것을 어디서 감지를 해야할지 몰라서
이미지뷰를 이용해 ACTION_DOWN으로 감지하도록 만들었습니다. 따로 Thread를 만들려니 아직 실력이 부족해 그것까지는 무리였습니다. ㅠ
이미지버튼에서는 ClickListener의 OnClick()은 버튼 위에서 ACTION_UP이 되어야 실행되어서 문제가 없었는데 이미지뷰에서 OnTouch()로 이미지 밖으로 나가서 ACTION_UP이 되는것을 어떻게 감지를 해야할까요? ㅠㅠ
public class SelfDiagActivity extends Activity implements OnClickListener {
ImageButton mainmenu;
ImageView monitor, desktop, mouse, keyboard;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO Auto-generated method stub
setContentView(R.layout.activity_selfdiag);
init();
}
private void init() {
// TODO Auto-generated method stub
mainmenu = (ImageButton) findViewById(R.id.diag_main_Button);
mainmenu.setBackgroundResource(R.drawable.diag_main_btn);
mainmenu.setOnClickListener(this);
monitor = (ImageView) findViewById(R.id.diag_monitor_button);
monitor.setClickable(true);
monitor.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
desktop.setImageResource(R.drawable.btn_diag_desktop_press);
mouse.setImageResource(R.drawable.btn_diag_mouse_press);
keyboard.setImageResource(R.drawable.btn_diag_keyboard_press);
}
else if(event.getAction()==MotionEvent.ACTION_UP)
{
Intent i = new Intent(getApplicationContext(), SelfDiagSecondActivity.class);
startActivity(i);
desktop.setImageResource(R.drawable.btn_diag_desktop);
mouse.setImageResource(R.drawable.btn_diag_mouse);
keyboard.setImageResource(R.drawable.btn_diag_keyboard);
}
return false;
}
});
desktop = (ImageView) findViewById(R.id.diag_desktop_button);
desktop.setClickable(true);
desktop.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
monitor.setImageResource(R.drawable.btn_diag_monitor_press);
mouse.setImageResource(R.drawable.btn_diag_mouse_press);
keyboard.setImageResource(R.drawable.btn_diag_keyboard_press);
}
else if(event.getAction()==MotionEvent.ACTION_UP)
{
Intent i = new Intent(getApplicationContext(), SelfDiagSecondActivity.class);
startActivity(i);
monitor.setImageResource(R.drawable.btn_diag_monitor);
mouse.setImageResource(R.drawable.btn_diag_mouse);
keyboard.setImageResource(R.drawable.btn_diag_keyboard);
}
return false;
}
});
mouse = (ImageView) findViewById(R.id.diag_mouse_button);
mouse.setClickable(true);
mouse.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
desktop.setImageResource(R.drawable.btn_diag_desktop_press);
monitor.setImageResource(R.drawable.btn_diag_monitor_press);
keyboard.setImageResource(R.drawable.btn_diag_keyboard_press);
}
else if(event.getAction()==MotionEvent.ACTION_UP)
{
Intent i = new Intent(getApplicationContext(), SelfDiagSecondActivity.class);
startActivity(i);
desktop.setImageResource(R.drawable.btn_diag_desktop);
monitor.setImageResource(R.drawable.btn_diag_monitor);
keyboard.setImageResource(R.drawable.btn_diag_keyboard);
}
return false;
}
});
keyboard = (ImageButton) findViewById(R.id.diag_keyboard_button);
keyboard.setClickable(true);
keyboard.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
desktop.setImageResource(R.drawable.btn_diag_desktop_press);
mouse.setImageResource(R.drawable.btn_diag_mouse_press);
monitor.setImageResource(R.drawable.btn_diag_monitor_press);
}
else if(event.getAction()==MotionEvent.ACTION_UP)
{
Intent i = new Intent(getApplicationContext(), SelfDiagSecondActivity.class);
startActivity(i);
desktop.setImageResource(R.drawable.btn_diag_desktop);
mouse.setImageResource(R.drawable.btn_diag_mouse);
monitor.setImageResource(R.drawable.btn_diag_monitor);
}
return true;
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
//Intent i;
if(v.getId() ==R.id.diag_main_Button){
finish();
break;
}
}
}