Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-在ExpandableListView的每一行的项目上设置侦听器_Java_Android_Listview_Listener - Fatal编程技术网

Java Android-在ExpandableListView的每一行的项目上设置侦听器

Java Android-在ExpandableListView的每一行的项目上设置侦听器,java,android,listview,listener,Java,Android,Listview,Listener,在每一行上我有两个EditText。当我更改第一个时,我希望另一个也被更改(如果需要,现在只需设置“25”进行测试)。我使用的是viewholder模式,并在每个第一个EditText上设置一个TextChangedListener,期望第二个也被更改。问题是,每当我更改任何行上的任何第一个编辑文本时,仅更改最后一行上的编辑文本。以下是适配器的代码(侦听器位于getgroupview中): 公共类CustomExpandableListAdapterWorkout扩展了BaseExpandabl

在每一行上我有两个EditText。当我更改第一个时,我希望另一个也被更改(如果需要,现在只需设置“25”进行测试)。我使用的是viewholder模式,并在每个第一个EditText上设置一个TextChangedListener,期望第二个也被更改。问题是,每当我更改任何行上的任何第一个编辑文本时,仅更改最后一行上的编辑文本。以下是适配器的代码(侦听器位于getgroupview中):

公共类CustomExpandableListAdapterWorkout扩展了BaseExpandableListAdapter{
私人语境;
私有列表expandableListTitle;
私有HashMap expandableListDetail;
私人儿童视图持有者儿童视图持有者;
私人组视图持有者组视图持有者;
公共CustomExpandableListAdapterNewWorkout(上下文上下文,列表expandableListTitle,
HashMap expandableListDetail){
this.context=上下文;
this.expandableListTitle=expandableListTitle;
this.expandableListDetail=expandableListDetail;
}
@凌驾
公共对象getChild(int listPosition,int expandedListPosition){
返回this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
.get(expandedListPosition);
}
@凌驾
公共长getChildId(int-listPosition、int-expandedListPosition){
返回expandedListPosition;
}
@凌驾
公共视图getChildView(int listPosition,最终int expandedListPosition,
布尔值isLastChild、视图转换视图、视图组父级){
最终字符串expandedListText=(字符串)getChild(listPosition,expandedListPosition);
String categoryName=(String)getGroup(listPosition);
if(convertView==null)
{
LayoutInflater LayoutInflater=(LayoutInflater)this.context
.getSystemService(上下文布局\充气机\服务);
convertView=LayoutFlater.充气(R.layout.list\u item\u exercise\u exercise,null);
childViewHolder=新的childViewHolder();
childViewHolder.mChildTitle=(TextView)convertView.findViewById(R.id.expandedListItem);
childViewHolder.mChildImage=(ImageView)convertView.findViewById(R.id.ImgExercisePic);
convertView.setTag(childViewHolder);
}
其他的
{
childViewHolder=(childViewHolder)convertView.getTag();
}
childViewHolder.mChildTitle.setText(expandedListText);
childViewHolder.mChildTitle.setTextAppearance(context,R.style.TitleStyle);
返回视图;
}
@凌驾
公共int getChildrenCount(int listPosition){
返回this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
.size();
}
@凌驾
公共对象getGroup(int listPosition){
返回此.expandableListTitle.get(listPosition);
}
@凌驾
public int getGroupCount(){
返回此.expandableListTitle.size();
}
@凌驾
公共长getGroupId(int-listPosition){
返回列表位置;
}
@凌驾
公共视图getGroupView(int listPosition,布尔值isExpanded,
视图(视图、视图组父级){
字符串listTitle=(字符串)getGroup(listPosition);
if(convertView==null)
{
LayoutInflater LayoutInflater=(LayoutInflater)this.context。
getSystemService(上下文布局\充气机\服务);
convertView=LayoutFlater.充气(R.layout.list\u group\u new\u Work\u exercise,空);
groupViewHolder=新的groupViewHolder();
groupViewHolder.mGroupTitle=(TextView)convertView.findViewById(R.id.exerciseName);
groupViewHolder.mMinSets=(EditText)convertView.findViewById(R.id.edtMinimumSets);
groupViewHolder.mMaxSets=(EditText)convertView.findViewById(R.id.edtMaxSets);
groupViewHolder.mMinSets.addTextChangedListener(新的TextWatcher(){
@凌驾
更改前文本之前的公共void(字符序列s、int start、int count、int after){
}
@凌驾
public void onTextChanged(字符序列、int start、int before、int count){
}
@凌驾
公共无效后文本已更改(可编辑){
groupViewHolder.mMaxSets.setText(“25”);
}
});
convertView.setTag(groupViewHolder);
}
其他的
{
groupViewHolder=(groupViewHolder)convertView.getTag();
}
groupViewHolder.mGroupTitle.setText(listTitle);
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共布尔值isChildSelectable(int listPosition,int expandedListPosition){
返回true;
}
公共最终类GroupViewHolder{
文本视图标题;
编辑文本MMINSET;
编辑文本集;
}
公共最终类ChildViewHolder{
文本视图mChildTitle;
ImageView-mChildImage;
}
}
可能有一些基本的东西我不了解适配器和视窗支架,我想知道解决它的正确方法。

好的,我的错。 应该在getGroupView方法中声明“GroupViewHolder GroupViewHolder”,这样每次都会创建一个新的侦听器,并影响其对应的行

public class CustomExpandableListAdapterNewWorkout extends BaseExpandableListAdapter {
    private Context context;
    private List<String> expandableListTitle;
    private HashMap<String, List<String>> expandableListDetail;

    private ChildViewHolder childViewHolder;
    private GroupViewHolder groupViewHolder;

    public CustomExpandableListAdapterNewWorkout(Context context, List<String> expandableListTitle,
                                                HashMap<String, List<String>> expandableListDetail) {
        this.context = context;
        this.expandableListTitle = expandableListTitle;
        this.expandableListDetail = expandableListDetail;
    }

    @Override
    public Object getChild(int listPosition, int expandedListPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
                .get(expandedListPosition);
    }

    @Override
    public long getChildId(int listPosition, int expandedListPosition) {
        return expandedListPosition;
    }

    @Override
    public View getChildView(int listPosition, final int expandedListPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String expandedListText = (String) getChild(listPosition, expandedListPosition);
        String categoryName= (String)getGroup(listPosition);

        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_item_exercises_exercise, null);

            childViewHolder = new ChildViewHolder();
            childViewHolder.mChildTitle =  (TextView) convertView.findViewById(R.id.expandedListItem);
            childViewHolder.mChildImage = (ImageView) convertView.findViewById(R.id.ImgExercisePic);

            convertView.setTag(childViewHolder);
        }
        else
        {
            childViewHolder = (ChildViewHolder) convertView.getTag();
        }
        childViewHolder.mChildTitle.setText(expandedListText);
        childViewHolder.mChildTitle.setTextAppearance(context,R.style.TitleStyle);




        return convertView;
    }
    @Override
    public int getChildrenCount(int listPosition) {
        return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
                .size();
    }

    @Override
    public Object getGroup(int listPosition) {
        return this.expandableListTitle.get(listPosition);
    }

    @Override
    public int getGroupCount() {
        return this.expandableListTitle.size();
    }

    @Override
    public long getGroupId(int listPosition) {
        return listPosition;
    }

    @Override
    public View getGroupView(int listPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {

        String listTitle = (String) getGroup(listPosition);

        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater) this.context.
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_group_new_workout_exercise, null);

            groupViewHolder = new GroupViewHolder();
            groupViewHolder.mGroupTitle = (TextView) convertView.findViewById(R.id.exerciseName);
            groupViewHolder.mMinSets = (EditText) convertView.findViewById(R.id.edtMinimumSets);
            groupViewHolder.mMaxSets = (EditText) convertView.findViewById(R.id.edtMaxSets);

            groupViewHolder.mMinSets.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    groupViewHolder.mMaxSets.setText("25");
                }

            });

            convertView.setTag(groupViewHolder);
        }
        else
        {
            groupViewHolder = (GroupViewHolder) convertView.getTag();
        }

        groupViewHolder.mGroupTitle.setText(listTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) {
        return true;
    }

    public final class GroupViewHolder {
        TextView mGroupTitle;
        EditText mMinSets;
        EditText mMaxSets;
    }

    public final class ChildViewHolder {
        TextView mChildTitle;
        ImageView mChildImage;

    }
}