How to customize ChannelView using Adapters
masterSince version 1.1.0, the recommended way to populate data and customize styles is using the Adapter pattern. The older inflateData() method and direct property setters are deprecated.
Adapter Hierarchy
StyleAdapter(Interface): The base interface defining data population and style implementation.BaseStyleAdapter(Abstract Class): Implements someStyleAdaptermethods; use this to avoid implementing every single method when creating custom styles.DefaultStyleAdapter(Class): ExtendsBaseStyleAdapterand provides the default implementation. Use this if you only want to override specific parts of the default look.
Implementation Workflow
- Create a class extending
BaseStyleAdapter(orDefaultStyleAdapter). - Implement
getChannelData()to return yourLinkedHashMap<String, List<Channel>>. - Override style methods like
setNormalStyle,setFixedStyle,setEditStyle, orsetFocusedStyleto apply custom layouts/colors via aViewHolder. - Register the adapter using
channelView.setStyleAdapter(yourAdapter).
// Example of extending BaseStyleAdapter
class MyAdapter extends BaseStyleAdapter<MyAdapter.MyViewHolder> {
@Override
public MyViewHolder createStyleView(ViewGroup parent, String channelName) {
// Inflate your custom layout here
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_custom_channel, null);
MyViewHolder customViewHolder = new MyViewHolder(inflate);
customViewHolder.tv.setText(channelName);
return customViewHolder;
}
@Override
public LinkedHashMap<String, List<Channel>> getChannelData() {
return data;
}
@Override
public void setNormalStyle(MyViewHolder viewHolder) {
viewHolder.tv.setBackgroundResource(R.drawable.bg_channel_custom_normal);
}
// ... other style overrides
}