2011-05-07 68 views
15

我有一个表单。 7垂直布局的EditText。在屏幕上只能看到3个EditText(表格很大,所以我需要上下滚动来填充所有文件)。在底部 - 按钮。Android Button需要双击才能执行操作

当我填充顶部的EditText(或顶部的一个,当我向下滚动到按钮时,这是不可见的),并将焦点(光标)放在这个EditText中,当我向下滚动并尝试点击Button一次时 - 没有任何反应。当我再次点击 - 发生按钮操作。

当两者的EditText重点和按钮可见 - 巴顿需要一个点击。

我认为,在第一种情况下首先单击只需要关注。第二次点击是“真实”点击。

我该如何解决它?我只需要点击一下按钮。由于

+0

你可以如何重复:与默认的活动 克里特空项目,使用此布局http://pastebin.ca/2054854 真实设备开始凸出 - 写文本顶部的EditText,向下滚动到按钮和点击按钮。 – newmindcore 2011-05-07 12:26:36

回答

20

的问题是旧的,我不知道这是否会解决你的问题,因为你的引擎收录链接不工作了,但因为我偶然发现了您的文章有同样的问题,我发现了一个解决方案,我会反正它张贴:

在我来说,当我应用自定义样式的按钮下面的教程问题发生:

<style name="ButtonStyle" parent="@android:style/Widget.Holo.Button"> 
    <item name="android:focusable">true</item> 
    <item name="android:focusableInTouchMode">true</item> 
    <item name="android:clickable">true</item> 
    <item name="android:background">@drawable/custom_button</item> 
    <item name="android:textColor">@color/somecolor</item> 
    <item name="android:gravity">center</item> 
</style> 

问题是以下行:

<item name="android:focusableInTouchMode">true</item> 

一旦我删除它,按钮按预期工作。

希望这会有所帮助。

+0

谢谢!为我修好了。 – locke 2014-04-26 11:30:16

+0

错误地发布在古老教程中的“focusableInTouchMode”已被复制粘贴到无数错误缠身的android应用程序中。 – 2014-08-03 21:54:40

10

我用下面来解决类似的问题。它会自动在该项目再次点击,如果第一次点击只获得焦点:

input.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      public void onFocusChange(View v, boolean hasFocus) { 
       if (hasFocus) { 
        v.performClick(); 
       } 
      } 
     }); 

我需要focusableInTouchMode是真实的。

+0

这不是一个热修复补丁吗?接受的答案不适合你? – Rajkiran 2014-08-25 10:06:33

+0

你如果需要,它是你需要有救了我的命的家伙:) – iBabur 2014-11-04 21:29:15

+0

@Rajkiran机器人:focusableInTouchMode =“真”,那么这个解决方案是完美的,在我的情况下,它是必须有focusableInTouchMode真 – iBabur 2014-11-04 21:30:39

1

到Maves回答类似。这对我来说诀窍:

<Button 
    style="@android:style/Widget.EditText" 
    android:focusableInTouchMode="false" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 
0

老问题我知道。无论如何,我有同样的问题,需要按钮是可以聚焦的。
最后我确实使用了一个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 e.g. if you don't want the control to get focus or other handlers.. 

     return false;     
    } 
}); 
相关问题