在点击/输入编辑文字后,我不知道如何删除编辑文字焦点。单击折叠按钮时应用程序停止运行。这是它给出的错误: -
致命例外:主程序:my.mimos.fssm.fosimapp,PID:3915 java.lang.IllegalArgumentException:参数必须是。的后代 这个观点在 android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4882)
我正在通过 bignerdranch 开展可扩展回收站视图。我的父列表视图包含 textview (列表名称)和折叠按钮(用作子视图的google)。至于我的孩子视图,我添加了一个 editText ,其中使用use来发表关于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());
}
}
});
}
}
我尝试了很多东西但不是它似乎对我有用。 这是我的可扩展回收站视图。enter image description here
答案 0 :(得分:1)
你可以使用这个库。 自定义RecyclerViewAdapters用于扩展和折叠组,支持多种视图类型。
ExpandableRecyclerView:
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
ExpandableCheckRecyclerView:
implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'