2016-12-23 8 views
1

カーソルの特定の値に応じて行レイアウトをカスタマイズする方法は?私はbindChildViewをカスタマイズする必要があると思いますが、どうですか? :)Android - SimpleCursorTreeAdapter - bindChildView override

主な機能:

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); 
      } 
     } 

私は残念ながらできませんでした、いくつかの例を探してみました; tは任意のを見つける - すべてのヘルプは

感謝を高く評価、 Jakub

答えて

0

私は大きなproffecionalではないが多分私のresea RCHあなたはこの

TextView textView = (TextView) view.findViewById(R.id.r_lv_name); 
textView.setBackgroundColor(Color.parseColor(color)); 
ようなものを使用することができます代わりにview.setBackgroundColorのも、私は#1B3F51B5 のような色の値を持つ特定の列の色を持っているあなたに私の場合は

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)); 
    } 

を助けることができます