Как добавить представление "заголовок" в верхней части каждого расширенного представления группы в ExpandableListView, заполненном SimpleCursorAdapter

Я использую ExpandableListView внутри одного из моих действий и заполняю дочернее и групповое представления (отдельные XML-файлы с несколькими текстовыми представлениями для каждого), используя собственный SimpleCursorAdapter. Мне кажется, что у меня есть следующие функциональные возможности: при щелчке по группе заполняется список дочерних элементов, а в позиции 0 дочернего списка заполняется дополнительный заголовок (два текстовых представления), который выступает в качестве заголовков каждого столбца данных, отображаемых дочерним элементом.,

Вот код для моего SimpleCursorAdapter и фрагмент соответствующего кода в моей деятельности:

SimpleCursorAdapter:

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;
}

}

Деятельность:

ExpandableListView expandablePayeeListView = (ExpandableListView) findViewById(R.id.payee_exp_list);

    mAdapter = new PayeeCursorAdapter(
            this,
            R.layout.list_group_payee,
            R.layout.list_item_payee_tx,
            new String[] {BillMeContract.PayeeEntry.COL_NAME},
            new int[] {R.id.payee_list_header},
            new String[] {BillMeContract.TransactionEntry.COL_DATE,
                          BillMeContract.TransactionEntry.COL_PAYMENT,
                          BillMeContract.TransactionEntry.COL_TYPE},
            new int[] {R.id.payee_list_item_date,
                       R.id.payee_list_item_amount,
                       R.id.payee_list_item_type});

    mAdapter.setViewBinder(new SimpleCursorTreeAdapter.ViewBinder() {

        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

            if(columnIndex == 4) {
                int type = cursor.getInt(columnIndex);
                TextView textView = (TextView) view;
                if(type == BillMeContract.TransactionEntry.TYPE_CASH) {
                    textView.setText(R.string.tx_spinner_type_cash);
                } else if (type == BillMeContract.TransactionEntry.TYPE_CHEQUE) {
                    textView.setText(R.string.tx_spinner_type_cheque);
                } else if (type == BillMeContract.TransactionEntry.TYPE_E_TRANSFER) {
                    textView.setText(R.string.tx_spinner_type_e_transfer);
                }
                return true;
            } else if(columnIndex == 3){
                String cost = String.format(Locale.CANADA, "%.2f", cursor.getDouble(columnIndex));
                cost = "$" + cost;
                TextView textView = (TextView) view;
                textView.setText(cost);
                return true;
            }
            return false;
        }
    });

    expandablePayeeListView.setAdapter(mAdapter);

0 ответов

Другие вопросы по тегам