2012-10-19 41 views
0

我有ListView的页眉和页脚。标题 - 是一个带有EditText和Spinners集合的长滚动视图。页脚中有两个按钮。当我点击一个EditText,然后点击页脚的按钮时,它不会触发。当我点击另一个标题的元素时,我看到了页脚按钮处理程序的结果。当我不点击这个EditText时,页脚的按钮正常工作。我的编辑文本:EditText点击禁用页脚元素点击

<EditText 
    android:id="@+id/orderTitle" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/levelSpin" 
    android:layout_marginTop="30dp" 
    android:text="Order title(specify)" 
    android:gravity="center_vertical|center_horizontal" /> 

我认为这个问题,editText点击disfocus页脚视图。于是,我就作出这样在我的按钮的setOnClickListener:

btnSubmitOrder.setOnClickListener(new View.OnClickListener() { 

    public void onClick(View view) { 
     footer.setFocusableInTouchMode(true); 
     deadline.setFocusable(false); 
     orderTitle.setFocusable(false); 
     header.clearFocus(); 
     btnSubmitOrder.setFocusable(true); 
     Log.i("new order button","fires"); 
     boolean errorFlag = false; 
    } 
}); 

但它并不能帮助。我也试着像这样:

orderTitle.setOnEditorActionListener(new OnEditorActionListener() { 

    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     if (actionId == EditorInfo.IME_ACTION_DONE) { 
      orderTitle.setFocusable(false); 
      Log.i("onEditorAction","yeah"); 
     } 
     Log.i("onEditorAction","yeah"); 
     return false; 
    } 
}); 

做disfocus这个EditText上,当用户的行为是成品,但它也没有帮助。我该如何解决这个问题?

回答

0

我用

btnSubmitOrder.setOnTouchListener(new OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_DOWN) 
         { 
        header.clearFocus(); 
         } 
        } 
     }); 
1

还有另一种选择和设置的页脚以下解决问题。有创造了另一个方法重载,但它并没有在文档上来(至少在我的IDE它没有),我只好在网上查询资料:

mylistView.addFooterView(footerView, null, **false**); 

其中假告诉页脚其不可选。我自己测试了这个,脚注内的按钮对触摸做出了响应。我希望这是一个可接受的答案。

否则,正如你所提到的,你将不得不使用ontouchlistener作为列表视图和按钮争夺焦点,而listview正在赢得胜利。这就是为什么当你点击列表视图时,按钮不再被触发,因为列表视图获得了焦点。