- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试仅在单击按钮时注册接近传感器监听器。但似乎什么也没有发生。我曾尝试在互联网上探索类似的东西,但什么也没得到。我究竟做错了什么?请帮忙!
xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/pushupbg"
android:orientation="vertical" >
<TextView
android:id="@+id/tvTitlePU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Push Up Counter"
android:textColor="#98f5ff"
android:textSize="25sp"
android:padding="10sp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/fragment1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<Button
android:id="@+id/bStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:typeface="serif"
android:onClick="startCounter"
android:text="Start" />
<Button
android:id="@+id/bStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:typeface="serif"
android:onClick="stopCounter"
android:text="Stop" />
<Button
android:id="@+id/bSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:typeface="serif"
android:onClick="saveData"
android:text="Save" />
</LinearLayout>
<TextView
android:id="@+id/tvCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTitlePU"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:text=""
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
这是java文件:
public class PushUp_Counter extends Activity implements SensorEventListener {
SensorManager smgr;
Sensor sensor;
Button start,stop,save;
TextView title,count;
int counter=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pushup_layout);
start=(Button)findViewById(R.id.bStart);
stop=(Button)findViewById(R.id.bStop);
save=(Button)findViewById(R.id.bSave);
title=(TextView)findViewById(R.id.tvTitlePU);
count=(TextView)findViewById(R.id.tvCount);
stop.setEnabled(false);
save.setEnabled(false);
}
public void startCounter(View v) {
// TODO Auto-generated method stub
smgr=(SensorManager)getSystemService(SENSOR_SERVICE);
sensor=smgr.getDefaultSensor(Sensor.TYPE_PROXIMITY);
smgr.registerListener(this, sensor,SensorManager.SENSOR_DELAY_NORMAL);
stop.setEnabled(true);
}
public void stopCounter(View v) {
// TODO Auto-generated method stub
smgr.unregisterListener(this);
save.setEnabled(true);
}
public void saveData(View v) {
// TODO Auto-generated method stub
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent arg0) {
// TODO Auto-generated method stub
if (arg0.values[0] == 0){
counter++;
count.setText("Your count is: "+counter);
}
}
}
日志猫:
06-19 00:01:21.780: W/EGL_genymotion(1493): eglSurfaceAttrib not implemented
06-19 00:01:29.396: I/ActivityManager(401): START u0 {cmp=com.example.fitgo/.PushUp_Counter} from pid 1493
06-19 00:01:29.412: W/genymotion_audio(125): out_write() limiting sleep time 44149 to 23219
06-19 00:01:29.452: W/genymotion_audio(125): out_write() limiting sleep time 55759 to 23219
06-19 00:01:29.472: W/genymotion_audio(125): out_write() limiting sleep time 67369 to 23219
06-19 00:01:29.504: W/genymotion_audio(125): out_write() limiting sleep time 58979 to 23219
06-19 00:01:29.524: W/genymotion_audio(125): out_write() limiting sleep time 40589 to 23219
06-19 00:01:29.548: W/genymotion_audio(125): out_write() limiting sleep time 32199 to 23219
06-19 00:01:29.572: W/genymotion_audio(125): out_write() limiting sleep time 23809 to 23219
06-19 00:01:29.856: D/dalvikvm(401): GC_FOR_ALLOC freed 441K, 17% free 13865K/16596K, paused 25ms, total 25ms
06-19 00:01:29.884: D/dalvikvm(401): GC_FOR_ALLOC freed 748K, 19% free 13487K/16596K, paused 22ms, total 22ms
06-19 00:01:29.884: D/MobileDataStateTracker(401): default: setPolicyDataEnable(enabled=true)
06-19 00:01:30.152: W/EGL_genymotion(1493): eglSurfaceAttrib not implemented
06-19 00:01:30.360: I/ActivityManager(401): Displayed com.example.fitgo/.PushUp_Counter: +458ms
06-19 00:01:34.372: W/genymotion_audio(125): out_write() limiting sleep time 44149 to 23219
06-19 00:01:34.396: W/genymotion_audio(125): out_write() limiting sleep time 55759 to 23219
06-19 00:01:34.424: W/genymotion_audio(125): out_write() limiting sleep time 47369 to 23219
06-19 00:01:34.448: W/genymotion_audio(125): out_write() limiting sleep time 38979 to 23219
06-19 00:01:34.492: W/genymotion_audio(125): out_write() limiting sleep time 31178 to 23219
06-19 00:01:38.448: W/genymotion_audio(125): out_write() limiting sleep time 44149 to 23219
06-19 00:01:38.468: W/genymotion_audio(125): out_write() limiting sleep time 55759 to 23219
06-19 00:01:38.496: W/genymotion_audio(125): out_write() limiting sleep time 47369 to 23219
06-19 00:01:38.516: W/genymotion_audio(125): out_write() limiting sleep time 38979 to 23219
06-19 00:01:38.564: W/genymotion_audio(125): out_write() limiting sleep time 31178 to 23219
最佳答案
像这样添加 onClickListener start.setOnClickListener(startCounter)
或者你也可以这样做
bStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startCounter(v);
}
});
让我们对您的代码进行更改,看看它是否与您的代码有关。
首先删除这行代码:
android:onClick="startCounter"
然后在您的 PushUp_Counter
类上将标题更改为:
public class PushUp_Counter extends Activity implements SensorEventListener, OnClickListener {
您必须在 onCreate()
中添加这行代码:
start.setOnClickListener(this);
然后你必须添加方法onClick()
,如下所示:
@Override
public void onClick(View v) {
// getId() returns this view's identifier.
switch(v.getId()){
case R.id.bStart;
// TODO Auto-generated method stub
smgr=(SensorManager)getSystemService(SENSOR_SERVICE);
sensor=smgr.getDefaultSensor(Sensor.TYPE_PROXIMITY);
smgr.registerListener(this, sensor,SensorManager.SENSOR_DELAY_NORMAL);
stop.setEnabled(true);
break;
}
}
如果代码的其余部分出现任何错误,请对其余代码进行注释,只需尝试此按钮并告诉我它是否有效。
关于java - 单击按钮时激活接近传感器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30922312/
我目前正在使用发现的重力脚本 here为了在我的网页上创建重力效果,我正在本地开发 atm。 我的问题是,重力效果的激活似乎是在鼠标移动时进行的,而我需要它在文档准备好时才触发。 google.cod
我正在尝试关注 Railsbridge Intallfest 并尝试将我的第一个 Rails 应用程序部署到 heroku。我不断收到以下错误消息: Gem::LoadError: Specified
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
Home-tab 是默认选中的,但是它的颜色是灰色的:( Home Bla Contact
我没有得到它的工作,我不知道为什么......遗憾的是其他问题 + 答案没有帮助。 测试设备: iPhone 6 iPad 2 相关代码: override func viewWillTransiti
我试图加载一个 View ,就像用户已经按下 UISearchBar 一样。我希望 SearchController 加载顶部的 UISearchBar 以及取消按钮。 我已经试过了: func ac
试图在 if whiteDotDist < centerRadius - whiteDotRadius 时获取代码执行它下面的所有代码都是事件的,并且当它下面的代码被执行时它再次变为非事件状态直到if
我正在使用 anaconda python。所以每次,在我的 mac 终端中,我输入终端命令: source /Users/mylaptop/anaconda/bin/activate /Users/
在我的 Angular 项目中,我有这种代码: this.swUpdate.available.subscribe(() => { ... }); 它工作正常,但给了我关于 activated 被
我想弄清楚 Julia 包是如何工作的,因为我喜欢容器化环境。我真的很挣扎。 在 python 中,我会做类似 conda create env --name ds 的事情创建环境然后安装容器化包我会
我的宏中有一些代码如下 ChDir File_pth Workbooks.Open filename:= File_pth & "\" & open_tkt Workbooks.Open filena
长话短说,我有两张纸,一张是“原始数据”,另一张是“结果”。我试图让结果表从“原始数据”表的每第七行中提取文本或数字,因此“结果”中的 A1 将是原始数据中的 A1,“结果”中的 A2 将是“原始数据
我不知道如何做到这一点,或者我是否可以做到这一点。我有一个 jQuery UI Accordion,多个部分,每个部分包含多个 anchor 标记,每个 anchor 标记都有一个唯一的字符串 id。
我不敢相信我还没有找到任何关于此的文档,但我想知道如何命令键盘激活并接收来自它的输入。我可以找到在编辑文本字段时操作弹出键盘的所有示例。谢谢 最佳答案 您还可以使用 UIKeyInput 协议(pro
我正在尝试为我的 Electron 应用程序生成NSIS安装程序的日志。为此,我创建了一个文件'logging.nsh'来定义LogSet和LogText宏。 以下是logging.nsh文件的代码:
几周前,我开始使用 typescript 和 knockoutJS,我有一个具体的问题,但我有解决方案,它太丑了,我无法忍受,但无法从中得到任何更好的东西,有太多代码需要粘贴,但我会尽力描述我的问题:
当我尝试激活我的虚拟环境时收到此错误即源 ~/edu-venv/bin/activate -bash: /home/vagrant/edu-venv/bin/activate: No such fil
要创建触发器,似乎必须发布它才能生效。但是发布需要对“协作”分支进行 PR,这意味着我们甚至在测试触发器是否实际工作之前就必须创建一个 PR,并且还必须创建多个后续 PR,直到我们获得正确的触发器。
我是最近的 IntelliJ Idea 用户,我不知道如何启用 Hibernate。当我右键单击我的项目时,Hibernate 不会出现在“添加框架支持”菜单中(实际上我唯一可以选择的技术是 Groo
要创建触发器,似乎必须发布它才能生效。但是发布需要对“协作”分支进行 PR,这意味着我们甚至在测试触发器是否实际工作之前就必须创建一个 PR,并且还必须创建多个后续 PR,直到我们获得正确的触发器。
我是一名优秀的程序员,十分优秀!