Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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
Android 使用ViewHolder时可展开列表视图隐藏项_Android_Expandablelistview_Show Hide_Android Viewholder - Fatal编程技术网

Android 使用ViewHolder时可展开列表视图隐藏项

Android 使用ViewHolder时可展开列表视图隐藏项,android,expandablelistview,show-hide,android-viewholder,Android,Expandablelistview,Show Hide,Android Viewholder,我正在编写一个应用程序,其中需要隐藏可扩展列表视图的元素 这就是我为实现这一目标所做的 public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) { CardHeaderInfo headerInfo = (CardHeaderInfo) getGroup(groupPosition); if (view ==

我正在编写一个应用程序,其中需要隐藏可扩展列表视图的元素

这就是我为实现这一目标所做的

public View getGroupView(int groupPosition, boolean isLastChild, View view,
            ViewGroup parent) {

        CardHeaderInfo headerInfo = (CardHeaderInfo) getGroup(groupPosition);
        if (view == null) {
            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inf.inflate(R.layout.card_group_view, null);
        }

        if(groupPosition < validChild) {
            TextView heading = (TextView) view.findViewById(R.id.heading);
            heading.setText(headerInfo.getName().trim());
        } else {
            view.setVisibility(View.INVISIBLE);
        }

        return view;
    }
为了优化这里的工作,我使用了这个概念,但如果开始滚动列表,元素会被洗牌,甚至一些变量会被隐藏视图所取代


在使用ViewHolder时,有没有办法解决这个问题?

我通过在visible Haven hide元素中添加另一行来解决这个问题:

if(groupPosition < validChild) {
            view.setVisibility(View.VISIBLE); ****
            TextView heading = (TextView) view.findViewById(R.id.heading);
            heading.setText(headerInfo.getName().trim());
        } else {
            view.setVisibility(View.INVISIBLE);
        }