Android可扩展列表视图最后一行子颜色更改

时间:2017-01-18 09:57:56

标签: android

我正在使用可扩展列表视图。在那,我需要改变最后一个孩子的文字颜色。我试过通过比较孩子的位置等于最后一行。条件工作文本颜色也在变化,但有时其他子颜色也在变化。所有行文本都是唯一的。如何使用这个孩子快速加载。我尝试使用自定义listview持有者。然后,它很快。但是,儿童文字颜色不起作用

public class ExpandableListAdapter扩展了BaseExpandableListAdapter {

        private Context _context;
        private List<String> _listDataHeader; // header titles
        // child data in format of header title, child title
        private HashMap<String, List<String>> _listDataChild;

        public ExpandableListAdapter(Context context,
                List<String> listDataHeader,
                HashMap<String, List<String>> listChildData) {
            this._context = context;
            this._listDataHeader = listDataHeader;
            this._listDataChild = listChildData;

        }

        @Override
        public Object getChild(int groupPosition, int childPosititon) {
            return this._listDataChild.get(
                    this._listDataHeader.get(groupPosition))
                    .get(childPosititon);
        }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        @Override
        public View getChildView(int groupPosition, final int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent) {

            final String childText = (String) getChild(groupPosition,
                    childPosition);

            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.list_item, null);
            }

            TextView li_tv_Subjects = (TextView) convertView
                    .findViewById(R.id.li_tv_Subjects);
            TextView li_tv_Grade = (TextView) convertView
                    .findViewById(R.id.li_tv_Grade);



            setControlsStyle.SetExpandableListViewChild(li_tv_Subjects);
            setControlsStyle.SetExpandableListViewChild(li_tv_Grade);


            li_tv_Subjects.setGravity(Gravity.LEFT | Gravity.CENTER);

            li_tv_Subjects.setText(childText.split(";")[0]);
            li_tv_Grade.setText(childText.split(";")[1]);

            if (childPosition==(listDataChild.size()-1))
{
li_tv_Subjects.setTextColor(android.r.color.blue);
li_tv_Grade.setTextColor(android.r.color.blue);
}



            return convertView;
        }

        @Override
        public int getChildrenCount(int groupPosition) {
            return this._listDataChild.get(
                    this._listDataHeader.get(groupPosition)).size();
        }

        @Override
        public Object getGroup(int groupPosition) {
            return this._listDataHeader.get(groupPosition);
        }

        @Override
        public int getGroupCount() {
            return this._listDataHeader.size();
        }

        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            String headerTitle = (String) getGroup(groupPosition);
            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.list_group, null);
            }

            TextView lblListHeader = (TextView) convertView
                    .findViewById(R.id.lblListHeader);
            lblListHeader.setText(headerTitle);
            setControlsStyle.SetExpandableListViewHeader(lblListHeader);
            lblListHeader.setGravity(Gravity.CENTER | Gravity.LEFT);
            TextView lg_tv_arrow = (TextView) convertView
                    .findViewById(R.id.lg_tv_arrow);



            return convertView;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    }

    private void prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("FA1");
        listDataHeader.add("FA2");
        listDataHeader.add("SA1");

        // Adding child data
        top250 = new ArrayList<String>();
        top250.add("English;A");
        top250.add("Tamil;A");
        top250.add("Maths;C");
        top250.add("Science;D");
        top250.add("Social;B");
        top250.add("Drawing;A");
        top250.add(getResources().getString(R.string.TotalPrecentage) + ";90");

        listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
        listDataChild.put(listDataHeader.get(1), top250);
        listDataChild.put(listDataHeader.get(2), top250);

    }

0 个答案:

没有答案
相关问题