我有一张表格。 7垂直布局中的EditText。 在一瞬间屏幕上只能看到3个EditText(forms很大,所以我需要向上和向下滚动以填充所有文件)。 在底部 – 按钮。
当我填充顶部的EditText(或者顶部的一个,当我向下滚动到按钮时它是不可见的),并且在此EditText中聚焦(光标),当我向下滚动并尝试单击按钮一次时 – 没有任何反应。 当我再次点击时 – 发生按钮动作。
当具有焦点和按钮的EditText都可见时 – 按钮需要单击一下。
我认为在第一种情况下,第一次点击只需要关注。 第二次点击是“真实”点击。
我该怎么办呢? 我只需要点击一下Button。 谢谢
问题是陈旧的,我不知道这是否会解决你的问题,因为你的粘贴箱链接不再起作用了,但是因为我偶然发现你的post有同样的问题而且我find了解决方案我会发布它:
在我的情况下,当我在教程后面的按钮上应用自定义样式时出现问题:
问题是以下几行:
true
一旦我删除它按钮按预期工作。
希望这可以帮助。
我使用以下方法来解决类似的问题。 如果第一次点击仅获得焦点,它会再次自动点击该项目:
input.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { v.performClick(); } } });
我需要focusableInTouchMode才是真的。
类似于Maves答案。 这对我有用:
老问题我知道。 无论如何我有同样的问题,需要按钮是可聚焦的。
最后我确实使用了OnTouchListener。
myButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action == MotionEvent.ACTION_DOWN) { // do your stuff on down here } else if (action == MotionEvent.ACTION_UP) { // do your stuff on up here } // if you return true then the event is not bubbled eg if you don't want the control to get focus or other handlers.. return false; } });