首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android - SimpleCursorTreeAdapter - bindChildView覆盖

Android - SimpleCursorTreeAdapter - bindChildView覆盖
EN

Stack Overflow用户
提问于 2016-12-23 17:11:30
回答 1查看 278关注 0票数 1

如何根据游标特定值自定义行布局?我想我需要定制bindChildView --但是如何定制呢?:)

主要功能:

代码语言:javascript
复制
public void fillQuestions(int id) {
        Cursor questionsCursor = db.getQuestions(id);
        EventActivity.this.startManagingCursor(questionsCursor);
        questionsCursor.moveToFirst();

        ExpandableListView questionsList = (ExpandableListView) findViewById(R.id.elv_questions);

        ExpandableQuestionsAdapter adapter = new ExpandableQuestionsAdapter(
                questionsCursor,
                EventActivity.this,
                R.layout.display_name_row,
                R.layout.display_cb_answer_row,
                new String[] {"questionText"},
                new int[] {R.id.r_lv_name},
                new String[] {"answerName"},
                new int[] {R.id.r_lv_cb_name});



    }

适配器:

代码语言:javascript
复制
    public class ExpandableQuestionsAdapter extends SimpleCursorTreeAdapter {


            public ExpandableQuestionsAdapter(Cursor cursor, Context context, int groupLayout,
                                              int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
                                              int[] childrenTo) {
                super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom, childrenTo);
            }

            @Override
            protected Cursor getChildrenCursor(Cursor groupCursor) {
                Cursor childCursor = db.getAnswers(groupCursor.getInt(groupCursor.getColumnIndex(KEY_F_ID)));
                EventActivity.this.startManagingCursor(childCursor);
                childCursor.moveToFirst();
                return childCursor;

            }

            @Override
            public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
                View rowView = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
                return rowView;
            }

            @Override
            protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
                super.bindChildView(view, context, cursor, isLastChild);
            }
        }

我试着找一些例子,不幸的是找不到任何帮助。

谢谢,雅各布

EN

回答 1

Stack Overflow用户

发布于 2017-02-27 05:44:57

我不是很专业,但也许我的研究可以帮助你。

代码语言:javascript
复制
protected void bindChildView(View view, Context context, Cursor getChildrenCursor, boolean isLastChild) {
        super.bindChildView(view, context, getChildrenCursor, isLastChild);
        //take value from getChildrenCursor but its also work with just cursor, because its already have correct position
        String color = getChildrenCursor.getString(getChildrenCursor.getColumnIndex(COLOR));
        //String color ="#1B3F51B5";
        view.setBackgroundColor(Color.parseColor(color));
    }

在我的例子中,我有一个特定的列颜色,它的颜色值类似于#1B3F51B5,您也可以使用如下所示的颜色来代替view.setBackgroundColor

代码语言:javascript
复制
TextView textView = (TextView) view.findViewById(R.id.r_lv_name);
textView.setBackgroundColor(Color.parseColor(color));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41298405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档