繁体   English   中英

仅当在 recyclerView 中编辑第一个时如何编辑第二个 editText

[英]how to edit 2nd editText only if the 1st is edited in recyclerView

我在recyclerView中使用editText,只有当第一个填充android java时,我才想显示或编辑第二个。

这是我的一个快速解决方案:在您的适配器中,创建一个标志 int currentFilled = -1; 并在您的editText被填充时更新此标志像这样:

        
        EditText edt1 = new EditText(this);
        edt1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
            @Override
            public void afterTextChanged(Editable s) { }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() >0){
                    // this is when your edt1 is filled
//                    edt2.setEnabled(true); // You can enable your edt2 or whatever here
//                    edt2.setVisibility(View.VISIBLE);
                    currentFilled = itemPosition;
                    notifyItemChanged(itemPosition+1) // position you wan to display or edit the edt
                } else {
                    // when edt1 is not filled
                    /// TODO do what ever you want
                }
            }
        });

然后在你的 ViewHolder 检查currentFilled == itemPosition-1
==>>

     edt.setEnabled(true); // You can enable your edt2 or whatever here 
    // or
     edt.setVisibility(View.VISIBLE)

根据您的要求,它可能会出现一些问题。 快乐编码:))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM