Sticklistheaderlistview

依賴

gethub鏈接地址

布局

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
        android:id="@+id/lv_pm"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

adapter

//實(shí)現(xiàn)StickyListHeadersAdapter
private class PmAdapter extends BaseAdapter implements StickyListHeadersAdapter {
    //重寫(xiě)getcount()
    @Override
    public int getCount() {

    }

    //重寫(xiě)getitem
    @Override
    public ProcessInfo getItem(int position) {
        return mInfos.get(position);
    }

    //重寫(xiě)getItemId()
    @Override
    public long getItemId(int position) {
        return 0;
    }
    //重寫(xiě)getHeaderView—返回對(duì)應(yīng)的頭布局

    /**
     * 2. * 給每一條數(shù)據(jù)返回一個(gè)對(duì)應(yīng)的 頭布局的view 相同的組返回的相同
     * 3. 
     */
    @Override
    public View getHeaderView(int position, View convertView,
                              ViewGroup parent) {
        if (convertView == null) {
            convertView = new TextView(getApplicationContext());
        }
        // 獲取一條數(shù)據(jù)bean
        ProcessInfo info = getItem(position);

        TextView tv = (TextView) convertView;
        tv.setTextColor(Color.BLACK);
        tv.setBackgroundColor(Color.parseColor("#CECFCE"));
        tv.setPadding(6, 6, 6, 6);
        if (info.isSys) {
            tv.setText("系統(tǒng)進(jìn)程(" + mSysInfos.size() + ")個(gè)");
        } else {
               tv.setText("用戶進(jìn)程(" + mUserInfos.size() + ")個(gè)");
        }
        return convertView;
    }

    //重寫(xiě)getHeaderId()—分組—有多少條目執(zhí)行多少次(條目和上個(gè)條目分組不一樣才添加分隔條目)
    @Override
    public long getHeaderId(int position) {
        //獲取數(shù)據(jù) 給每一條數(shù)據(jù)返回一個(gè) long 值 代表不同的分組
        return info.isSys ? 0 : 1;
    }

    //重寫(xiě)getview
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 普通數(shù)據(jù)
        ViewHolder viewHolder;
        if (convertView == null) {
            // 緩存view是空的 生成新的布局view
            convertView = View.inflate(getApplicationContext(), R.layout.item_pm, null);
            viewHolder = new ViewHolder();
            // 獲取所有的控件 放到viewHolder里
            viewHolder.ivIcon = (ImageView) convertView
                    .findViewById(R.id.iv_ip_icon);
            // 把viewHolder存到convertView里
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        // 賦值

        return convertView;
    }
}

static class ViewHolder {
    ImageView ivIcon;
    TextView tvName;
    TextView tvMemSize;
    CheckBox mCb;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容