Back to project page RSSNewsReaderApp.
The source code is released under:
GNU General Public License
If you think the Android project RSSNewsReaderApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.romanostrechlis.rssnews.auxiliary; // w w w . j a v a 2s .c o m import java.util.HashMap; import java.util.List; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckedTextView; import android.widget.ExpandableListView; import android.widget.ImageView; import android.widget.TextView; import com.romanostrechlis.rssnews.R; import com.romanostrechlis.rssnews.content.RssFeed; /** * Custom BaseExpandableListAdapter for the creation of the List in MainActivity. * * @author Romanos Trechlis * */ public class ExpCustomListAdapter extends BaseExpandableListAdapter { private List<String> parentItems; private Context context; private HashMap<String, List<RssFeed>> childMap; public ExpCustomListAdapter(List<String> parents, HashMap<String, List<RssFeed>> childMap, Context context) { this.parentItems = parents; this.childMap = childMap; this.context = context; } @Override public int getGroupCount() { return this.parentItems.size(); } @Override public int getChildrenCount(int groupPosition) { return this.childMap.get(this.parentItems.get(groupPosition)).size(); } @Override public Object getGroup(int groupPosition) { return this.parentItems.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return this.childMap.get(this.parentItems.get(groupPosition)) .get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.layout_parents, parent, false); } CheckedTextView ctv = (CheckedTextView)convertView.findViewById(R.id.ctv1); ctv.setTextColor(Color.parseColor("#f5f5f5")); ctv.setText(parentItems.get(groupPosition)); ctv.setChecked(isExpanded); return convertView; } @SuppressLint("InflateParams") @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { //child = (List<String>) childItems.get(groupPosition); RssFeed feed = (RssFeed)getChild(groupPosition, childPosition); final String childText = feed.getName(); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.layout_row, null); } TextView tvExpLabel = (TextView) convertView.findViewById(R.id.tvExpLabel); tvExpLabel.setTextColor(Color.WHITE); ImageView ivExpIcon = (ImageView) convertView.findViewById(R.id.ivExpIcon); tvExpLabel.setText(childText); if (feed.getNewContent()) { // ivExpIcon.setImageResource(android.R.drawable.button_onoff_indicator_on); ivExpIcon.setImageResource(R.drawable.ic_new_style); } else { // ivExpIcon.setImageResource(android.R.drawable.button_onoff_indicator_off); } return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } }