Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.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/4/jquery-ui/2.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可扩展列表视图_Java_Android_Listview - Fatal编程技术网

Java Android可扩展列表视图

Java Android可扩展列表视图,java,android,listview,Java,Android,Listview,我正在活动中使用ExpandableListView。我在组视图中有一个文本视图和一个复选框。单击复选框时,相应的列表项会根据其状态展开或折叠。我不想在单击GroupView中的复选框时更改列表项的状态。我怎样才能做到这一点 这是我的布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:lay

我正在
活动中使用
ExpandableListView
。我在
组视图中有一个
文本视图
和一个
复选框
。单击
复选框时,相应的列表项会根据其状态展开或折叠。我不想在单击GroupView中的复选框时更改列表项的状态。我怎样才能做到这一点

这是我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ExpandableListView
            android:id="@+id/expandableListView"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottomPanel"
            android:dividerHeight="0.5dp"
            android:drawSelectorOnTop="false"
            android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorRight" />

        <LinearLayout
            android:id="@+id/bottomPanel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">

            <Button
                android:id="@+id/bt_delete_group"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="@string/delete_group" />

            <Button
                android:id="@+id/bt_add_group"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="@string/add_group" />

            <Button
                android:id="@+id/bt_show_select"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="@string/show_select" />

        </LinearLayout>
    </RelativeLayout>
</FrameLayout>

这是我的适配器:

这是我编辑后的适配器:

public class CustomExpandableListAdapter extends BaseExpandableListAdapter {

    private Context context;
    private List<String> expandableListTitle;
    private HashMap<String, List<RowBean>> expandableListDetail;
    public static ArrayList<Integer> selected = new ArrayList<>();
    private Realm realm = Realm.getDefaultInstance();

    public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
                                       HashMap<String, List<RowBean>> 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) {
//        for(RowBean r : expandableListDetail.get(expandableListTitle.get(listPosition))){
//            Log.e("is select " , r.getTitle() + " " +r.isSelected() + " , " + listPosition + " ," +expandedListPosition);
//        }
        RowBean rowBean = (RowBean) getChild(listPosition, expandedListPosition);
        RowBean rowBean1 = expandableListDetail.get(expandableListTitle.get(listPosition)).get(expandedListPosition);
//        Log.e("rowbean " , rowBean1.getTitle() + " , " + rowBean1.isSelected() );
        final String expandedListText = rowBean.getTitle();
        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_item_holder, null);
        }
        TextView expandedListTextView = (TextView) convertView.findViewById(R.id.expandedListItem);
        CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.expandedListItemCheckbox);
        expandedListTextView.setText(expandedListText);
        checkBox.setChecked(rowBean.isSelected());
        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(final int listPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        final ViewGroup groupview = parent;

        SharedPreferences pref = context.getSharedPreferences("MAIN_PREF", MODE_PRIVATE);
        final SharedPreferences.Editor editor = pref.edit();
        final String listTitle = (String) getGroup(listPosition);
        boolean[] sel = {RealmController.getGroup(listTitle, realm).isSelect()};
        if (convertView == null) {
            LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//            convertView = layoutInflater.inflate(R.layout.list_group, null);

            convertView = layoutInflater.inflate(R.layout.holder_layout, null);
        }
//        TextView listTitleTextView = (TextView) convertView
//                .findViewById(R.id.listTitle);

        TextView listTitleTextView = (TextView) convertView.findViewById(R.id.showTextHolder);
        final CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkBoxHolder);
//        checkBox.setSelected(true);
//        if (pref.getInt(listTitle, 0) == 1) {
//            checkBox.setSelected(true);
//        } else {
//            checkBox.setSelected(false);
//        }

        final boolean[] st = new boolean[1];
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if (!checkBox.isChecked()) {
//                    ExpandableListView gExpandableListView = (ExpandableListView) groupview;
//                    gExpandableListView.expandGroup(listPosition);
////                    checkBox.setChecked(false);
//                    RealmResults<ObjectsInGroupRealm> objectsInGroupRealms = RealmController.getObjects(realm, listTitle);
//                    int position = -1;
//                    for (ObjectDefExtends objectDefExtends : Singleton.getInstance().getListaODE()) {
//                        for (ObjectsInGroupRealm o : objectsInGroupRealms) {
//                            if (o.getName().equals(objectDefExtends.name)) {
//                                position = Singleton.getInstance().getListaODE().indexOf(objectDefExtends);
//                                Singleton.getInstance().getListaODE().get(position).visible = false;
//                                editor.putInt(Singleton.getInstance().getListaODE().get(position).id.toString(), 0);
//                                editor.apply();
//                                RealmController.updateGroup(o.getGroupName(), false, realm);
//                                RealmController.updateObjectsInGroupRealm(o.getGroupName(), realm, context, false);
//                                FragmentGroupObjectsActivity.getArgument(context);
//                            }
//                        }
//                    }
//                    selected.remove(Integer.valueOf(listPosition));
//                } else {
//                    ExpandableListView gExpandableListView = (ExpandableListView) groupview;
//                    gExpandableListView.expandGroup(listPosition);
////                    checkBox.setChecked(true);
//                    selected.add(listPosition);
//                    RealmResults<ObjectsInGroupRealm> objectsInGroupRealms = RealmController.getObjects(realm, listTitle);
//                    int position = -1;
//                    for (ObjectDefExtends objectDefExtends : Singleton.getInstance().getListaODE()) {
//                        for (ObjectsInGroupRealm o : objectsInGroupRealms) {
//                            if (o.getName().equals(objectDefExtends.name)) {
//                                position = Singleton.getInstance().getListaODE().indexOf(objectDefExtends);
//                                Singleton.getInstance().getListaODE().get(position).visible = true;
//                                editor.putInt(Singleton.getInstance().getListaODE().get(position).id.toString(), 1);
//                                editor.apply();
//                                RealmController.updateGroup(o.getGroupName(), true, realm);
//                                st[0] = true;
//                                checkBox.setChecked(true);
//                                RealmController.updateObjectsInGroupRealm(o.getGroupName(), realm, context, true);
//                                FragmentGroupObjectsActivity.getArgument(context);
//                            }
//                        }
//                    }
//                }
//                FragmentGroupObjectsActivity.getArgument(context);
//                FragmentAllObjectActivity.getArgument(context);
//                notifyDataSetChanged();
            }
        });

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked) {
//                    checkBox.setChecked(false);
                    RealmResults<ObjectsInGroupRealm> objectsInGroupRealms = RealmController.getObjects(realm, listTitle);
                    int position = -1;
                    for (ObjectDefExtends objectDefExtends : Singleton.getInstance().getListaODE()) {
                        for (ObjectsInGroupRealm o : objectsInGroupRealms) {
                            if (o.getName().equals(objectDefExtends.name)) {
                                position = Singleton.getInstance().getListaODE().indexOf(objectDefExtends);
                                Singleton.getInstance().getListaODE().get(position).visible = false;
                                editor.putInt(Singleton.getInstance().getListaODE().get(position).id.toString(), 0);
                                editor.apply();
                                RealmController.updateGroup(o.getGroupName(), false, realm);
                                RealmController.updateObjectsInGroupRealm(o.getGroupName(), realm, context, false);
                                FragmentGroupObjectsActivity.getArgument(context);
                            }
                        }
                    }
                    selected.remove(Integer.valueOf(listPosition));
                } else {
//                    checkBox.setChecked(true);
                    selected.add(listPosition);
                    RealmResults<ObjectsInGroupRealm> objectsInGroupRealms = RealmController.getObjects(realm, listTitle);
                    int position = -1;
                    for (ObjectDefExtends objectDefExtends : Singleton.getInstance().getListaODE()) {
                        for (ObjectsInGroupRealm o : objectsInGroupRealms) {
                            if (o.getName().equals(objectDefExtends.name)) {
                                position = Singleton.getInstance().getListaODE().indexOf(objectDefExtends);
                                Singleton.getInstance().getListaODE().get(position).visible = true;
                                editor.putInt(Singleton.getInstance().getListaODE().get(position).id.toString(), 1);
                                editor.apply();
                                RealmController.updateGroup(o.getGroupName(), true, realm);
                                st[0] = true;
                                checkBox.setChecked(true);
                                RealmController.updateObjectsInGroupRealm(o.getGroupName(), realm, context, true);
                                FragmentGroupObjectsActivity.getArgument(context);
                            }
                        }
                    }
                }
                FragmentGroupObjectsActivity.getArgument(context);
                FragmentAllObjectActivity.getArgument(context);
                notifyDataSetChanged();
            }
        });

        listTitleTextView.setTypeface(null, Typeface.BOLD);
        listTitleTextView.setText(listTitle);
        checkBox.setChecked(RealmController.getGroup(listTitleTextView.getText().toString(), realm).isSelect());

        return convertView;
    }

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

    @Override
    public boolean isChildSelectable(int listPosition, int expandedListPosition) {
        return true;
    }
}
公共类CustomExpandableListAdapter扩展了BaseExpandableListAdapter{
私人语境;
私有列表expandableListTitle;
私有HashMap expandableListDetail;
选定的公共静态ArrayList=新建ArrayList();
私有领域Realm=Realm.getDefaultInstance();
公共CustomExpandableListAdapter(上下文、列表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、视图convertView、视图组父视图){
//for(RowBean r:expandableListDetail.get(expandableListTitle.get(listPosition))){
//Log.e(“is select”,r.getTitle()+“”+r.isSelected()+”,“+listPosition+”,“+expandedListPosition”);
//        }
RowBean RowBean=(RowBean)getChild(listPosition,expandedListPosition);
RowBean rowBean1=expandableListDetail.get(expandableListTitle.get(listPosition)).get(expandedListPosition);
//Log.e(“rowbean”,rowBean1.getTitle()+”,“+rowBean1.isSelected());
最后一个字符串expandedListText=rowBean.getTitle();
if(convertView==null){
LayoutInflater LayoutInflater=(LayoutInflater)this.context
.getSystemService(上下文布局\充气机\服务);
convertView=LayoutFlater.充气(R.layout.list\u item\u holder,空);
}
TextView expandedListTextView=(TextView)convertView.findViewById(R.id.expandedListItem);
复选框=(复选框)convertView.findViewById(R.id.expandedListItemCheckbox);
expandedListTextView.setText(expandedListText);
setChecked(rowBean.isSelected());
返回视图;
}
@凌驾
公共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(最终整型列表位置、布尔isExpanded、视图转换视图、视图组父级){
最终视图组组视图=父视图;
SharedReferences pref=context.getSharedReferences(“主首选”,模式专用);
最终SharedReferences.Editor=pref.edit();
最终字符串listTitle=(字符串)getGroup(listPosition);
布尔[]sel={RealmController.getGroup(listTitle,realm.isSelect()};
if(convertView==null){
LayoutInflater LayoutInflater=(LayoutInflater)this.context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
//convertView=LayoutFlater.充气(R.layout.list\u组,空);
convertView=LayoutFlater.充气(R.layout.holder_layout,null);
}
//TextView listTitleTextView=(TextView)convertView
//.findViewById(R.id.listTitle);
TextView listTitleTextView=(TextView)convertView.findViewById(R.id.showTextHolder);
最终复选框CheckBox=(复选框)convertView.findViewById(R.id.checkBoxHolder);
//复选框.setSelected(true);
//if(pref.getInt(listTitle,0)==1){
//复选框.setSelected(true);
//}其他{
//复选框.setSelected(false);
//        }
最终布尔值[]st=新布尔值[1];
checkBox.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//如果(!checkBox.isChecked()){
//ExpandableListView gExpandableListView=(ExpandableListView)组视图;
//gExpandableListView.expandGroup(listPosition);
////checkBox.setChecked(false);
//RealmResults ObjectsGroupRealms=RealmController.getObjects(领域,列表标题);
//int位置=-1;
//对于(ObjectDefExtends ObjectDefExtends:Singleton.getInstance().getListaODE()){
//for(ObjectSingGroupRealm o:ObjectSingGroupRealms){
//if(o.getName().equals(objectDefExtends.name)){
//position=Singleton.getInstance().getListaODE().indexOf(objectDefExtends);
//Singleton.getInstance().getListaODE().get(position).visible=false;
//putInt(Singleton.getInstance().getListaODE().get(position).id.toString(),0);
//editor.apply();
//RealmController.updateGroup(o.getGroupName(),false