android,我如何给这个定义好的layout添加OnTouchListener 触摸事件?,现在没反应啊
publicclassMainActivityextendsActivityimplementsOnTouchListener{privateTextViewsunCal...
public class MainActivity extends Activity implements OnTouchListener {
private TextView sunCal, lunarCal, updateTime, realTemp, realWeather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sunCal = (TextView) findViewById(R.id.sunCal);
lunarCal = (TextView) findViewById(R.id.lunarCal);
updateTime = (TextView) findViewById(R.id.updateTime);
realTemp = (TextView) findViewById(R.id.realTemp);
realWeather = (TextView) findViewById(R.id.realWeather);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(MainActivity.this, "发生触摸事件", Toast.LENGTH_LONG).show();
return true;
}
}
是点击屏幕的任一部分,对于layout来说的 展开
private TextView sunCal, lunarCal, updateTime, realTemp, realWeather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sunCal = (TextView) findViewById(R.id.sunCal);
lunarCal = (TextView) findViewById(R.id.lunarCal);
updateTime = (TextView) findViewById(R.id.updateTime);
realTemp = (TextView) findViewById(R.id.realTemp);
realWeather = (TextView) findViewById(R.id.realWeather);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(MainActivity.this, "发生触摸事件", Toast.LENGTH_LONG).show();
return true;
}
}
是点击屏幕的任一部分,对于layout来说的 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询