我正在制作一个电子商务应用程序,它的购物车列表有一个自定义的ListView,由EditText组成。EditText表示项目的数量。我使用OnFocusChangeListener来检测客户何时完成了更改项目的数量,然后在服务器上更新购物车。一切都很好,只是onFocusChange被叫了两次,也就是我得到了两次false。
viewHolder.etProductQuantity.setOnFocusChangeListener( new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if(!hasFocus){
            // Updating the ProductList class's object to set the new quantity
            // Updating product quantity on server
            Log.d("Product Quantity", viewHolder.etProductQuantity.getText().toString() + b);
        }
    }
});因此,代码被执行了两次,这就产生了问题。
发布于 2014-11-24 08:37:23
在清单中的活动中添加以下行修复了问题:
 android:windowSoftInputMode="adjustPan"但不知道为什么。
发布于 2014-11-24 08:37:50
你可以这样使用:
edt_sys_log_search.setOnEditorActionListener(new OnEditorActionListener() {        
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(actionId==EditorInfo.IME_ACTION_DONE){
                    //do calling WS                 
                }
                return false;
            }
        });并将EditText属性设置为:
android:imeOptions="actionDone"
singleLine="true"当用户按下SoftKeyboard完成时,它将调用WS
发布于 2014-11-24 08:41:47
尝试维护一个标志,其中检查丢失了,焦点代码执行了一次,然后再也不执行了:
viewHolder.etProductQuantity.setTag(1);
viewHolder.etProductQuantity.setOnFocusChangeListener( new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if(!hasFocus && ((Integer)view.getTag())==1){
                    // Updating the ProductList class's object to set the new quantity
                    // Updating product quantity on server
                    Log.d("Product Quantity",                    
                    viewHolder.etProductQuantity.getText().toString() + b);
                    view.setTag(0);
                }else{
                    view.setTag(1);
                }
            }
        });https://stackoverflow.com/questions/27100534
复制相似问题