Java 是否触摸功能屏幕
我找不到解决办法。。。 如果未触摸屏幕,我希望运行firstfunc()Java 是否触摸功能屏幕,java,android,eclipse,screen,Java,Android,Eclipse,Screen,我找不到解决办法。。。 如果未触摸屏幕,我希望运行firstfunc() 我有firstfunc(),如果触摸屏幕,我不想运行它 为此,我需要返回真或假的布尔函数来确定屏幕是否被触摸。 我尝试和myView.setOnTouchListener(and public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return super.onTouc
我有firstfunc(),如果触摸屏幕,我不想运行它 为此,我需要返回真或假的布尔函数来确定屏幕是否被触摸。 我尝试和
myView.setOnTouchListener(
and
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return super.onTouchEvent(event);
}
但这不是我想要的…试试这个:
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>
OnTouchListener
上执行,其中设置了一个标志类MyActivity扩展了活动在TouchListener上的实现
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;
}
}
你到底想要什么?只有在触摸屏幕时才能调用“onTouchEvent”,否则屏幕不会被触摸!我想先运行func()如果屏幕没有被触摸基本上你不能,你怎么知道屏幕什么时候没有被触摸,屏幕只是一个接收用户触摸信号的工具,如果用户没有触摸它,根本就没有信号,所以屏幕基本上一直没有被触摸。很抱歉,你不能这样做。干杯!我有func(){}如果触摸屏,我不想运行它如果触摸屏标志为true;如果我不触摸屏,如何设置标志为false?在类级别声明布尔标志,默认情况下其值为false。标志的false值将指示未触摸屏。