How to get data from Edit Text in a RecyclerView?

前端 未结 3 1127
挽巷
挽巷 2021-02-05 19:05

I have recyclerview with edit text. Each row has a edit text. I am entering values in the edit text manually and after i enter values, I want to get those values in each and eve

3条回答
  •  迷失自我
    2021-02-05 19:16

    To do this there are two ways:-

    1) Add save Button in each row of RecyclerView on this Button click (onClick)

     @Override
            public void onClick(View v) {
               String ans = holher.numPicker.getText().toString();
               // save ans to sharedpreferences or Database
            }
    

    2) Add onTextChangedListener to EditText

    holher.mumPicker.addTextChangedListener(new TextWatcher() {
    
       public void afterTextChanged(Editable s) {}
    
       public void beforeTextChanged(CharSequence s, int start,
         int count, int after) {
       }
    
       public void onTextChanged(CharSequence s, int start,
         int before, int count) {
          String ans = holher.numPicker.getText().toString();
               // save ans to sharedpreferences or Database
       }
      });
    

    Then in your MainActivity.java retrive data from sharedpreferences or database

提交回复
热议问题