簡體   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