Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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/8/selenium/4.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 StickyListHeaderListView多选模式问题_Android_Android Listview_Sticky_Sectionheader - Fatal编程技术网

Android StickyListHeaderListView多选模式问题

Android StickyListHeaderListView多选模式问题,android,android-listview,sticky,sectionheader,Android,Android Listview,Sticky,Sectionheader,我正在使用github中的android库来开发我的应用程序。它工作得很好。在我实现了用于复制和删除元素的多选模式侦听器之后,元素的高亮显示出现了问题 每当我选择一个元素并上下滚动时,一些节标题会自动高亮显示,如下图所示 如何避免这种行为。有什么我遗漏的步骤吗?需要一些人帮忙解决这个问题 下面给出了扩展StickyListHeadersAdapter的适配器 public class MessageStickyAdapter extends BaseAdapter implements

我正在使用github中的android库来开发我的应用程序。它工作得很好。在我实现了用于复制和删除元素的多选模式侦听器之后,元素的高亮显示出现了问题

每当我选择一个元素并上下滚动时,一些节标题会自动高亮显示,如下图所示

如何避免这种行为。有什么我遗漏的步骤吗?需要一些人帮忙解决这个问题

下面给出了扩展StickyListHeadersAdapter的适配器

    public class MessageStickyAdapter extends BaseAdapter implements StickyListHeadersAdapter, SectionIndexer {

        private final Context mContext;
        private List<Msg> messages;
        private int[] mSectionIndices;
        private String[] mSectionDates;
        private LayoutInflater mInflater;

        public MessageStickyAdapter(Context context,List<Msg> listMessages) {
            mContext = context;
            mInflater = LayoutInflater.from(context);
            messages = listMessages;
            mSectionIndices = getSectionIndices();
            mSectionDates = getSectionDates();
        }

        private int[] getSectionIndices() {
            ArrayList<Integer> sectionIndices = new ArrayList<>();
            String lastDate = messages.get(0)._msg_date;
            sectionIndices.add(0);
            for (int i = 1; i < messages.size(); i++) {
               if (!messages.get(i)._msg_date.equalsIgnoreCase(lastDate)) {
               Log.d("LastDate,Newdate",lastDate + ',' +messages.get(i)._msg_date);
               lastDate = messages.get(i)._msg_date;
               sectionIndices.add(i);
               }
            }
            int[] sections = new int[sectionIndices.size()];
            for (int i = 0; i < sectionIndices.size(); i++) {
                sections[i] = sectionIndices.get(i);
            }
            Log.d("Sections",String.valueOf(sections.length));
            return sections;
        }

        private String[] getSectionDates() {
             String[] dates = new String[mSectionIndices.length];
             for (int i = 0; i < mSectionIndices.length; i++) {
                 dates[i] = messages.get(i)._msg_date;
                 Log.d("Dates",dates[i]);
             }
                 return dates;
        }

        @Override
        public int getCount() {
            return messages.size();
        }

        @Override
        public Object getItem(int position) {
            return messages.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = mInflater.inflate(R.layout.right, parent, false);
                holder.text = (TextView) convertView.findViewById(R.id.msgr);
                holder.time = (TextView) convertView.findViewById(R.id.tim);
                convertView.setTag(holder);
             } else {
                holder = (ViewHolder) convertView.getTag();
             }
            try {
                holder.text.setText(URLDecoder.decode( messages.get(position)._msg_content, "UTF-8"));
                holder.text.setTag(messages.get(position).getMsgID());
                holder.time.setText(messages.get(position)._msg_time);
             } catch (UnsupportedEncodingException e) {
                 e.printStackTrace();
             }

             return convertView;
        }

        @Override
        public View getHeaderView(int position, View convertView, ViewGroup parent) {
            HeaderViewHolder holder;

            if (convertView == null) {
               holder = new HeaderViewHolder();
               convertView = mInflater.inflate(R.layout.date_separator, parent, false);
               holder.text = (TextView) convertView.findViewById(R.id.textSeparator);
               convertView.setTag(holder);
            } else {
               holder = (HeaderViewHolder) convertView.getTag();
            }
            String headerText = messages.get(position)._msg_date;
            holder.text.setText(headerText);
            return convertView;
         }

        /**
         * Remember that these have to be static, postion=1 should always return
         * the same Id that is.
         */
        @Override
        public long getHeaderId(int position) {
            // return the first character of the country as ID because this is what
            // headers are based upon
            return getSectionForPosition(position);
        }

        @Override
        public int getPositionForSection(int section) {
            if (mSectionIndices.length == 0) {
               return 0;
            }
            if (section >= mSectionIndices.length) {
                section = mSectionIndices.length - 1;
            } else if (section < 0) {
               section = 0;
            }
            return mSectionIndices[section];
        }

        @Override
        public int getSectionForPosition(int position) {
            for (int i = 0; i < mSectionIndices.length; i++) {
               if (position < mSectionIndices[i]) {
               return i - 1;
               }
            }
           return mSectionIndices.length - 1;
        }

        @Override
        public Object[] getSections() {
           return mSectionDates;
        }

        public void clear() {
           messages.clear();
           mSectionIndices = new int[0];
           mSectionDates = new String[0];
           notifyDataSetChanged();
        }

        public void restore(List<Msg> newMessages)
        {
           messages.clear();
           mSectionIndices = new int[0];
           mSectionDates = new String[0];
           messages = newMessages;
           mSectionIndices = getSectionIndices();
           mSectionDates = getSectionDates();
           notifyDataSetChanged();
        }

        public void add(Msg newMessage)
        {
           messages.add(0,newMessage);
           mSectionIndices = getSectionIndices();
           mSectionDates = getSectionDates();
        }

        class HeaderViewHolder {
           TextView text;
        }

        class ViewHolder {
           TextView text;
           TextView time;
        }
    }
公共类MessageStickyAdapter扩展BaseAdapter实现StickyListHeadersAdapter,SectionIndexer{
私有最终上下文mContext;
私人列表消息;
私有int[]msactionindex;
私有字符串[]MSActionDates;
私人停车场;
public MessageStickyAdapter(上下文上下文,列表消息){
mContext=上下文;
mInflater=LayoutInflater.from(上下文);
消息=列表消息;
msectionindex=getsectionindex();
mSectionDates=getSectionDates();
}
私有int[]getSectionIndexes(){
ArrayList SectionIndexs=新的ArrayList();
字符串lastDate=messages.get(0)。\u msg\u date;
增加(0);
对于(int i=1;i=msectionindex.length){
截面=msectionindex.length-1;
}else if(截面<0){
截面=0;
}
返回msectionindex[节];
}
@凌驾
公共int getSectionForPosition(int位置){
对于(int i=0;i