0

I don't know how to remove edit text focus after I clicked / type on the edit text. The application stopped running when I clicked on the collapse button. This is the error it gives out:-

FATAL EXCEPTION: main Process: my.mimos.fssm.fosimapp, PID: 3915 java.lang.IllegalArgumentException: parameter must be a descendant of this view at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4882)

I'm working on expandable recycler view by bignerdranch. My parent list view has a textview (the name of the list) and a collapse button (where it act as google for the child view). As for my child view, I added a editText, where use is enable to leave a comment regarding the textview.

ExpandableAdapter.java

import com.bignerdranch.expandablerecyclerview.Adapter.ExpandableRecyclerAdapter;
import com.bignerdranch.expandablerecyclerview.Model.ParentListItem;

public class ATPExpandableAdapter extends ExpandableRecyclerAdapter<ATPParentViewHolder, ATPChildViewHolder> {

    LayoutInflater mInflater;
    Context mContext;
    ArrayList<ATPParent> mParentItemList;
    public static final String TAG = ATPExpandableAdapter.class.getSimpleName();

    public ATPExpandableAdapter(Context context, ArrayList<ATPParent> parentItemList) {
        super(parentItemList);
        mInflater = LayoutInflater.from(context);
        mContext = context;
        mParentItemList = parentItemList;
    }

    @Override
    public ATPParentViewHolder onCreateParentViewHolder(ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.list_item_atp_parent, viewGroup, false);
        return new ATPParentViewHolder(view);
    }

    @Override
    public ATPChildViewHolder onCreateChildViewHolder(ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.list_item_atp_child, viewGroup, false);
        return new ATPChildViewHolder(view);
    }

//    todo: continued here
    @Override
    public void onBindParentViewHolder(final ATPParentViewHolder atpParentViewHolder, final int i, ParentListItem parentObject) {
        ATPParent atpParent = (ATPParent) parentObject;
        atpParentViewHolder.mATP_textview.setText(atpParent.getTitle());

        //when user clicked on parent view
        atpParentViewHolder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: parentView");
            }
        });

        atpParentViewHolder.mParentDropDownArrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick: expandable button");
            }
        });

    }

    @Override
    public void onBindChildViewHolder(final ATPChildViewHolder atpChildViewHolder, int i, Object childObject) {
        final ATPChild atpChild = (ATPChild) childObject;


        String text = atpChildViewHolder.mCatatanInput.getText().toString();
        if(!text.equals("")) {
            atpChild.setDetail(text);
            atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
        } else {
            atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
        }

        atpChildViewHolder.mCatatanInput.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    atpChild.setDetail(atpChildViewHolder.mCatatanInput.getText().toString());
                    atpChildViewHolder.mCatatanInput.setText(atpChild.getDetail());
                }
            }
        });

    }
}

I tried a lot of thing but not of it seemed to work for me. This is my expandable recycler view.enter image description here

  • i don't know how to call editText focus from chilhdviewholder inside ParentViewHolder... any ideas? The focus should be gone after user comment or collapse the parent view. – Hibiki Ryou Oct 30 '17 at 03:59
  • the error happened because the editText still has focus when, user clicked on collapse button. (missing view) – Hibiki Ryou Oct 30 '17 at 04:01
  • `public ATPParentViewHolder(View itemView) { mView = itemView; mATP_textview = (TextView) itemView.findViewById(R.id.input_atp); mParentDropDownArrow = (ImageButton) itemView.findViewById(R.id.parent_list_item_expand_arrow); mParentDropDownArrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isExpanded()) { collapseView(); } else { expandView(); } } });` – Hibiki Ryou Oct 30 '17 at 04:06

1 Answers1

1

Expandable RecyclerView

you can use this library. It is very Useful Custom RecyclerViewAdapters for expanding and collapsing groups with support for multiple view types.

ExpandableRecyclerView:

implementation 'com.thoughtbot:expandablerecyclerview:1.3'

ExpandableCheckRecyclerView:

implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'

https://github.com/thoughtbot/expandable-recycler-view

Custom Expand / Collapse Animations example

Shomu
  • 2,734
  • 24
  • 32