簡體   English   中英

如何將標題行添加到使用simplecursortreeadapter的expandablelistview的子視圖列表中

[英]How to add a header row to a list of child views of an expandablelistview that uses simplecursortreeadapter

我正在使用一個simplecursortreeadapter來填充一個expandablelistview,並希望在所有具有數據標題的子視圖的頂部都有一行。

  1. 組1名稱[展開]
    • 標頭(日期,名稱,$)
    • 兒童1(07/12/2017,乍得,50.00)
    • 兒童2(08/11/2017,邁克,63.21)
  2. 組2名稱[展開]
    • 標頭(日期,名稱,$)
    • 兒童1(03/25/2017,肯,23.97)
    • 兒童2(01/25/2017,Will,101.11)
  3. 第3組[合攏]

是否可以使包含3組標題文本(日期,名稱,$)的文本視圖僅在組展開時出現? 由於SimpleCursorTreeAdapter負責將游標數據添加到視圖中,因此我不確定如何向其中添加行或如何實現這一點。 這可能嗎?

編輯:這是我的適配器類:

package com.example.myproject.michaelc.billme;

import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.support.v4.content.Loader;
import android.util.Log;
import android.widget.SimpleCursorTreeAdapter;

import com.example.myproject.michaelc.billme.data.BillMeContract;

import java.util.HashMap;

public class PayeeCursorAdapter extends SimpleCursorTreeAdapter {

private final String LOG_TAG = getClass().getSimpleName();
private PayeeActivity mActivity;
protected final HashMap<Integer, Integer> mGroupMap;

// No cursor is added to the adapter so that it only runs when the CursorLoader runs, instead of every time the activity does
public PayeeCursorAdapter(
        Context context,        // The activity where the adapter will be running
        int groupLayout,        // The .xml layout file for the group layout
        int childLayout,        // The .xml layout file for the child layout
        String[] groupFrom,     // String of column names in the cursor that is the data for each group item
        int[] groupTo,          // The ID of the views in the group layout that display the column from the groupFrom String[]
        String[] childrenFrom,  // String of column names in the cursor that is the data for each child item
        int[] childrenTo) {     // The ID of the views in the child layout that display the column from the childFrom String[]

    super(context, null, groupLayout, groupFrom, groupTo, childLayout, childrenFrom, childrenTo);
    mActivity = (PayeeActivity) context;
    mGroupMap = new HashMap<Integer, Integer>();
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {

    int groupPos = groupCursor.getPosition();
    int groupId = groupCursor.getInt(groupCursor.getColumnIndex(BillMeContract.PayeeEntry._ID));

    Log.d(LOG_TAG, "getChildrenCursor() for groupPos " + groupPos);
    Log.d(LOG_TAG, "getChildrenCursor() for groupId " + groupId);

    mGroupMap.put(groupId, groupPos);
    Loader<Cursor> loader = mActivity.getSupportLoaderManager().getLoader(groupId);

    if(loader != null && !loader.isReset()) {
        mActivity.getSupportLoaderManager().restartLoader(groupId, null, mActivity);
    } else {
        mActivity.getSupportLoaderManager().initLoader(groupId, null, mActivity);
    }
    return null;
}

public HashMap<Integer, Integer> getGroupMap(){
    return mGroupMap;
}
}

是的,有可能。

您還可以看到此鏈接,希望得到解決方案。

http://www.worldbestlearningcenter.com/tips/Android-expandable-listview-header.htm

package android.widget.expandablelistview;

import android.os.Bundle;
import android.util.ExpandableListScenario;
import android.widget.Button;
import android.widget.ExpandableListView;

public class ExpandableListWithHeaders extends ExpandableListScenario {
private static final int[] sNumChildren = {1, 4, 3, 2, 6};
private static final int sNumOfHeadersAndFooters = 12;

@Override
protected void init(ExpandableParams params) {
    params.setStackFromBottom(false)
            .setStartingSelectionPosition(-1)
            .setNumChildren(sNumChildren)
            .setItemScreenSizeFactor(0.14)
            .setConnectAdapter(false);
}

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final ExpandableListView expandableListView = getExpandableListView();
    expandableListView.setItemsCanFocus(true);

    for (int i = 0; i < sNumOfHeadersAndFooters; i++) {
        Button header = new Button(this);
        header.setText("Header View " + i);
        expandableListView.addHeaderView(header);
    }

    for (int i = 0; i < sNumOfHeadersAndFooters; i++) {
        Button footer = new Button(this);
        footer.setText("Footer View " + i);
        expandableListView.addFooterView(footer);
    }

    // Set adapter here AFTER we set header and footer views
    setAdapter(expandableListView);
}

/**
 * @return The number of headers (and the same number of footers)
 */
public int getNumOfHeadersAndFooters() {
    return sNumOfHeadersAndFooters;
}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM