public class ImageVT2 extends Activity 
implements View.OnTouchListener {
    private ImageView iv;
    
    /*private static final int IMGS[] = {
    R.drawable.ys01, R.drawable.ys02, R.drawable.ys03,
    R.drawable.ys04, R.drawable.ys05, R.drawable.ys06,
    R.drawable.ys07, R.drawable.ys08, R.drawable.ys09,
    R.drawable.ys10, R.drawable.ys11, R.drawable.ys12,
    R.drawable.ys13, R.drawable.ys14, R.drawable.ys15,
    R.drawable.ys16, R.drawable.ys17, R.drawable.ys18,
    R.drawable.ys19, R.drawable.ys20, R.drawable.ys21
    };*/
    private Field fields[] = R.drawable.class.getFields();
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv = (ImageView)findViewById(R.id.ImageView01);       
        iv.setOnTouchListener(this);
    }
    int i = 0;
    float x1, x2, y1, y2;
    @Override
public boolean onTouch(View v, MotionEvent event) {  
   
    if(event.getAction() == MotionEvent.ACTION_DOWN){
    x1 = event.getX();
    y1 = event.getY();
   
    //Log.i("(x1, y1)", "("+x1+", "+y1+")");
}else if(event.getAction() == MotionEvent.ACTION_UP){
x2 = event.getX();
    y2 = event.getY();
   
    //Log.i("(x2, y2)", "("+x2+", "+y2+")");
    float valueX = x1 - x2;
    if(valueX > 0){
    //if(i >= (IMGS.length-1) ) i = -1;
    if(i >= (fields.length-1) ) i = -1;
    i++;
    }else if(valueX < 0){
    //if(i <= 0) i = (IMGS.length);
    if(i <= 0) i = (fields.length);
    i--;
    }  
   
//iv.setImageResource(IMGS[i]);
    try{
    iv.setImageResource(fields[i].getInt(new Object()));
    }catch(Exception e){}
}
   
    return true;
}
}

중요한 부분 색 표시 했어요. 

'스마트폰 > 안드로이드' 카테고리의 다른 글

LifeCycle 공부.  (0) 2011.05.13
묵시적 intent 공부.  (0) 2011.05.13
이미지뷰(ImageView) 공부.  (0) 2011.05.13
웹 소스 찍기  (0) 2011.05.13
데이터 바인딩4 공부  (0) 2011.05.13

+ Recent posts