Java Android-SimpleCursorTreeAdapter-bindChildView覆盖
如何根据光标特定值自定义行布局?我想我需要自定义bindChildView-但如何自定义?:) 主要功能:Java Android-SimpleCursorTreeAdapter-bindChildView覆盖,java,android,cursor,android-cursoradapter,Java,Android,Cursor,Android Cursoradapter,如何根据光标特定值自定义行布局?我想我需要自定义bindChildView-但如何自定义?:) 主要功能: public void fillQuestions(int id) { Cursor questionsCursor = db.getQuestions(id); EventActivity.this.startManagingCursor(questionsCursor); questionsCursor.moveToFirst();
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});
}
适配器:
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);
}
}
我试图寻找一些例子,不幸的是,我找不到;I don’我找不到任何帮助
谢谢,
雅库布我不是一个专业人士,但也许我的研究可以帮助你
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
TextView textView = (TextView) view.findViewById(R.id.r_lv_name);
textView.setBackgroundColor(Color.parseColor(color));
我不是专业人士,但也许我的研究可以帮助你
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
TextView textView = (TextView) view.findViewById(R.id.r_lv_name);
textView.setBackgroundColor(Color.parseColor(color));