[Solved] Pass value from View Holder


Then create a hashmap and whenever updation takes place save the data in hashmap.

  • Inherit getItem(int index) method in adapter with HashMap as return type & and return the data in that method for corresponding index.

    HashMap<String, Object> hashMap = new HashMap<String, Object>();
    
    @Override
    public HashMap getItem(int i) {
    return hashMap.get(i);
    }
    
  • Like if user types something in edittext then use textChangeListener for that button & onTextChange save the data in hashmap for corresponding index.

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    
        }
    
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    hashMap.put(position, editText.getText().toString());
        }
    
        @Override
        public void afterTextChanged(Editable editable) {
    
        }
    });
    

then in onClick of button in activity write below code.

for (int i = 0; i < listView.getAdapter().getCount(); i++) {
        HashMap hashMap = (HashMap) listView.getAdapter().getItem(i);
        }

6

solved Pass value from View Holder