Android 在模拟器中测试触摸功能
我尝试为android开发一个应用程序。我有以下代码:Android 在模拟器中测试触摸功能,android,debugging,touch,Android,Debugging,Touch,我尝试为android开发一个应用程序。我有以下代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CardImage = (ImageView)findViewById(R.id.CardImage); CardImage.setOnTouchListener(this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CardImage = (ImageView)findViewById(R.id.CardImage);
CardImage.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_UP)
{
System.out.println("Touch!");
}
return true;
}
如何在模拟器中调试Ontouch函数?我试图用鼠标拖动图像开关,但什么也没发生
谢谢你的帮助 尝试此代码(注意:未测试)
它刚刚使用了以下代码
public class TestTouch extends Activity implements View.OnTouchListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.flag); // my image
iv.setOnTouchListener(this);
setContentView(iv);
}
public boolean onTouch(View v, MotionEvent event)
{
System.out.println(event.getAction());
if(event.getAction() == MotionEvent.ACTION_UP)
{
System.out.println("Touch!");
}
return true;
}
}
您的活动是否实现了onTouchListener?
public class TestTouch extends Activity implements View.OnTouchListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.flag); // my image
iv.setOnTouchListener(this);
setContentView(iv);
}
public boolean onTouch(View v, MotionEvent event)
{
System.out.println(event.getAction());
if(event.getAction() == MotionEvent.ACTION_UP)
{
System.out.println("Touch!");
}
return true;
}
}