2013-07-03 5 views
0

Button과 일부 TextView와 EditText가 포함 된 ScrollView 내부에 RelativeLayout이 있습니다.Android 버튼은 발사하는데 두 번 클릭하는 데 항상 걸림 onClick()

내 xml 레이아웃 파일에서 android : onClick을 정의하지만 버튼을 두 번 클릭하여 이벤트를 발생시킵니다. 버튼은 항상 첫 번째 클릭에 초점을 맞추고 두 번째 클릭시 onClick 이벤트를 발생시킵니다. focusable 및 focusableInTouchMode를 false로 설정하려고 시도했지만 동작이 변경되지 않습니다. 여기

내 레이아웃 파일 다음 포커스와 focusableIn TouchMode를 아무 짓도하지 않는 것 이유에

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".DensityActivity" > 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
     ... 

     <TextView 
     ... 

     <TextView 
     ... 

     <EditText 
     ... 

     <Button 
      android:id="@+id/ad_button_calculate" 
      android:layout_width="112dp" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/ad_edit_obs_temp" 
      android:layout_alignParentRight="true" 
      android:layout_marginTop="20pt" 
      android:paddingLeft="6pt" 
      android:onClick="onClick" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:text="@string/button_calculate" /> 

     <TextView 
     ... 

    </RelativeLayout> 
</ScrollView> 

어떤 아이디어 나 제안?

내 onClick() 메소드가해야 할 일이 아닌 것 같아서 그냥보고 뭔가 간단하게 줄 였고 똑같이 동작합니다. 다음은 단순화 된 onClick()입니다.

public void onClick(View view) { 

    new AlertDialog.Builder(this).setTitle("Argh").setMessage("Watch out!").setNeutralButton("Close", null).show(); 

} 
+1

'onClick()'을 게시하십시오. 'Button'에'focusable'가 필요하지 않아야합니다. 우리가 알지 못하는 무언가가 있다면 말입니다. – codeMagic

+0

흠, 새 프로젝트에서 같은 레이아웃을 사용하면 잘 작동합니다. 당신 말이 맞습니다. 내가 모르는 뭔가가 있어야합니다. 나는 계속 조사 할 것이다. – plisskin

+0

프로젝트를 정리할 수 있습니다. "Project -> Clean ..." – codeMagic

답변

4

좋아, 찾았습니다. 물론, 그것은 내 자신의 실수였습니다. 내에서 onCreate 메소드의 끝에 나는이 일을했다 :

// Set the focus to the calculate button so the keyboard won't show up automatically 
Button calcButton = (Button)findViewById(R.id.ac_button_calculate); 
calcButton.setFocusable(true); 
calcButton.setFocusableInTouchMode(true); 
calcButton.requestFocus(); 

물론 그래서, 아무리 내 xml 파일에 무슨 짓을했는지, 내 코드를 무시하지 않았다. 좋은 작품

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

: 대신, 키보드를 숨기려면이를 사용했다.

+0

xml이나 스타일 파일에 focusable과 focusableInTouchMode를 false로 넣으려고 했습니까? 나는이 똑같은 문제가 있었고 이것은 나에게 해결되었다. 창 전체를 할 필요가 없다. –

관련 문제