我找不到解决方案...... 如果没有触摸屏幕,我想运行firstfunc() 我有firstfunc()我不想在触摸屏幕时运行它
对于它我需要布尔函数返回true或false以确定是否触摸屏幕。
我尝试了myView.setOnTouchListener(
和
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return super.onTouchEvent(event);
}
但这不是我想要的......
答案 0 :(得分:0)
试试这个:
public class MyActivity extends Activity implements OnTouchListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
//the whole screen becomes sensitive to touch
mLinearLayoutMain = (LinearLayout) findViewById(R.id.layout_main);
mLinearLayoutMain.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event)
{
// put your code in here
return false;//false indicates the event is not handled
}
}
layout.xml中的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_main">
<!-- your other views go here-->
</LinearLayout>
答案 1 :(得分:0)
OnTouchListener
上实施。 class MyActivity extends Activity implements OnTouchListener
View senceTouch;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
senceTouch = findViewById(R.id.view_id);
senceTouch.setOnTouchListener(this)
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// set flag here
return true;
}
}