gpt4 book ai didi

java - 父View折叠时如何清除子ViewHolder焦点?

转载 作者:行者123 更新时间:2023-12-02 12:04:22 26 4
gpt4 key购买 nike

我不知道在单击/键入编辑文本后如何删除编辑文本焦点。当我单击折叠按钮时,应用程序停止运行。这是它给出的错误:-

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)

我正在研究 bignerdranch 的可扩展回收器 View 。我的父 ListView 有一个textview(列表的名称)和一个折叠按钮(它充当 subview 的google)。至于我的 subview ,我添加了一个editText,其中可以使用该 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());
}
}
});

}
}

我尝试了很多东西,但似乎没有一个对我有用。这是我的可扩展回收器 View 。 enter image description here

最佳答案

可扩展的RecyclerView

你可以使用这个库。这是非常有用的自定义 RecyclerViewAdapters,用于扩展和折叠组并支持多种 View 类型。

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

关于java - 父View折叠时如何清除子ViewHolder焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47007946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com