import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnTouchListener;
import android.widget.*;
public class SingleTouchTest extends Activity implements OnTouchListener
{
StringBuilder builder = new StringBuilder();
TextView textView;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("Touch and drag (one finger only)!");
textView.setOnTouchListener(this);
setContentView(textView);
}
@Override
public boolean onTouch(View v, MotionEvent event)
{
builder.setLength(0);
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
builder.append("down, ");
break;
case MotionEvent.ACTION_MOVE:
builder.append("move, ");
break;
case MotionEvent.ACTION_CANCEL:
builder.append("cancel, ");
break;
case MotionEvent.ACTION_UP:
builder.append("up, ");
break;
}
builder.append(event.getX());
builder.append(", ");
builder.append(event.getY());
String text = builder.toString();
textView.setText(text);
return true;
}
}
import android.os.*;
import android.view.*;
import android.view.View.OnTouchListener;
import android.widget.*;
public class SingleTouchTest extends Activity implements OnTouchListener
{
StringBuilder builder = new StringBuilder();
TextView textView;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText("Touch and drag (one finger only)!");
textView.setOnTouchListener(this);
setContentView(textView);
}
@Override
public boolean onTouch(View v, MotionEvent event)
{
builder.setLength(0);
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
builder.append("down, ");
break;
case MotionEvent.ACTION_MOVE:
builder.append("move, ");
break;
case MotionEvent.ACTION_CANCEL:
builder.append("cancel, ");
break;
case MotionEvent.ACTION_UP:
builder.append("up, ");
break;
}
builder.append(event.getX());
builder.append(", ");
builder.append(event.getY());
String text = builder.toString();
textView.setText(text);
return true;
}
}
'코드조각모음' 카테고리의 다른 글
[android004] 키입력 예제 (0) | 2011.11.06 |
---|---|
[android003] 멀티 터치 예제 (0) | 2011.11.06 |
[android001] 액티비티 생명 주기 예제 (0) | 2011.11.06 |
[Java006] Boxing & Unboxing (0) | 2011.10.12 |
[Java005] Primitive 데이터 타입 (0) | 2011.10.12 |