If you think the Android project android_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* ******************************************************************************
* Copyright (c) 2013-2014 Gabriele Mariotti.
*/*fromwww.java2s.com*/
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* *****************************************************************************
*/package it.gmariotti.cardslib.library.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ExpandableListView;
import android.widget.ListAdapter;
import it.gmariotti.cardslib.library.R;
import it.gmariotti.cardslib.library.internal.CardExpandableListAdapter;
/**
* @author Gabriele Mariotti (gabri.mariotti@gmail.com)
*/publicclass CardExpandableListView extends ExpandableListView{
protectedstatic String TAG = "CardExpandableListView";
/**
* CardExpandableListAdapter
*/protected CardExpandableListAdapter mAdapter;
//--------------------------------------------------------------------------
// Custom Attrs
//--------------------------------------------------------------------------
/**
* Default layout to apply to card
*/protectedint list_card_layout_resourceID = R.layout.list_card_layout;
//--------------------------------------------------------------------------
// Constructors
//--------------------------------------------------------------------------
public CardExpandableListView(Context context) {
super(context);
init(null, 0);
}
public CardExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public CardExpandableListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
//--------------------------------------------------------------------------
// Init
//--------------------------------------------------------------------------
/**
* Initialize
*
* @param attrs
* @param defStyle
*/protectedvoid init(AttributeSet attrs, int defStyle){
//Init attrs
initAttrs(attrs,defStyle);
//Set divider to 0dp
setDividerHeight(0);
}
/**
* Init custom attrs.
*
* @param attrs
* @param defStyle
*/protectedvoid initAttrs(AttributeSet attrs, int defStyle) {
list_card_layout_resourceID = R.layout.list_card_layout;
TypedArray a = getContext().getTheme().obtainStyledAttributes(
attrs, R.styleable.card_options, defStyle, defStyle);
try {
list_card_layout_resourceID = a.getResourceId(R.styleable.card_options_list_card_layout_resourceID, this.list_card_layout_resourceID);
} finally {
a.recycle();
}
}
//--------------------------------------------------------------------------
// Adapter
//--------------------------------------------------------------------------
/**
* Set the adapter. You can provide a {@link it.gmariotti.cardslib.library.internal.CardArrayAdapter}, or a {@link it.gmariotti.cardslib.library.internal.CardCursorAdapter}
* or a generic adapter.
* Pay attention: your generic adapter has to call {@link it.gmariotti.cardslib.library.internal.CardArrayAdapter#getView} method
*
* @param adapter
*/
@Override
publicvoid setAdapter(ListAdapter adapter) {
if (adapter instanceof CardExpandableListAdapter){
setAdapter(adapter);
}else {
Log.w(TAG, "You are using a generic adapter. Pay attention: your adapter has to call cardArrayAdapter#getView method");
super.setAdapter(adapter);
}
}
/**
* Set {@link CardExpandableListAdapter} and layout used by items in ListView
*
* @param adapter {@link CardExpandableListAdapter}
*/publicvoid setAdapter(CardExpandableListAdapter adapter) {
super.setAdapter(adapter);
//Set Layout used by items
adapter.setGroupLayoutId(list_card_layout_resourceID);
adapter.setCardListView(this);
mAdapter=adapter;
}
}