2012-05-29 2 views
1

У меня есть ExpandableListView в действии. Код:Как установить цвет дочернего текста ExpandableListView

final ExpandableListView expandableListView = (ExpandableListView)findViewById(R.id.expandableListView1); 
    expandableListView.setDivider(null); 
    expandableListView.setCacheColorHint(0); 
    expandableListView.setGroupIndicator(null); 
    final EEInterviewExpandableListAdapter adapter = new EEInterviewExpandableListAdapter(this); 
    expandableListView.setAdapter(adapter); 

и родственный код в адаптере:

public View getChildView(int groupPosition, int childPosition, 
     boolean isLastChild, View convertView, ViewGroup parent) { 
    String string = pageArray.get(groupPosition).get(childPosition); 
    boolean highlight=false; 
    return getChildGenericView(string,highlight);  
} 
public TextView getChildGenericView(String string,boolean highlight)  
{  
    // Layout parameters for the ExpandableListView  
    AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams( 
      ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
    TextView text = new TextView(activity);  
    text.setLayoutParams(layoutParams);  
    // Center the text vertically  
    text.setGravity(Gravity.CENTER | Gravity.LEFT);  
    // Set the text starting position  
    text.setPadding(0, 2, 0, 2);  
    text.setText(string.trim());  
    text.setBackgroundResource(R.drawable.childsep); 
    if(highlight) 
     text.setTextColor(R.color.expchdhighlightcolor); 
    else 
     text.setTextColor(R.color.expchdcolor); 
    text.setTextSize(EEEnv.EEfontSize); 
    return text;  
}  

Моя проблема заключается в SetTextColor() не работает. Я искал в Интернете. И сказано, что expandableListView.setCacheColorHint (0); может разрешить его. Но проблема все еще существует. Кто-нибудь знает эту проблему?

ответ

0

Вам необходимо получить доступ к определенным XML-ресурсов, как это:

text.setTextColor(getResources().getColor(R.color.expchdhighlightcolor)); 

В противном случае вы передаете уникальный идентификатор, который ссылается на ресурс ... Обратите внимание на разницу, когда вы запустите это:

Log.v("Test", "Not what I expected: " + R.color.expchdhighlightcolor); 
Log.v("Test", "The hex value in decimal: " + getResources().getColor(R.color.expchdhighlightcolor)); 
+0

Sam , благодаря. Я попробую. – David

+0

Он работает! Огромное спасибо. – David

Смежные вопросы