2014-01-24 1 views
1

내가 작업하고있는 응용 프로그램은 텍스트가 무거워서 확장 가능한 목록이 몇 개 있으므로 다차원 배열을 사용하여 하위 뷰를 채 웁니다. 다음과 같이 텍스트의 특정 부분을 굵게 표시하고 싶습니다. 예 1 : 이것은 예입니다.Html.fromHtml() 텍스트 서식 및 다차원 배열

CharSequence example = Html.fromHtml(getString(R.string.example); 

그 톤을 상상하고 내 배열에 맞게 :

<string name="example"><![CDATA[<b>Example 1:</b> This is an example.]]></string> 

이상 내 어댑터에 : 그래서이 일을, 나는 나의 strings.xml의이이

private CharSequence [][] childview = { 
    {example, example1, example2, example3}; 
    {example4, example5, example6, example7}; 
}; 

질문 : 전체 변수 세트를 만드는 것보다 더 나은 방법이 있어야할까요? 내 문자열을 문자열 배열로 만들고 Html.fromHtml 서식을 사용하여 다차원 배열에 맞출 수 있습니까?

+0

의 A [] []보다 [] 더 – njzk2

+0

나의 나쁜, editted. – Racepace

답변

0

당신은 약간의 유틸리티 메소드 작성할 수 있습니다

public CharSequence [][] fromRes(int[][] resIdMatrix) { 
    CharSequence[][] result = new CharSequence[resIdMatrix.length][]; 
    int i = 0; 
    for (int[] resIds : resIdMatrix) { 
     CharSequence[] row = result[i++] = new CharSequence[resIds.length]; 
     int j = 0; 
     for (int id : resIds) { 
      row[j++] = Html.fromHtml(getString(id)); 
     } 
    } 
    return result; 
} 

을 그리고 자원 ID의 2 차원 배열로 전화 :

int[][] resIds = { 
    {R.string.example, R.string.example1, R.string.example2, R.string.example3}, 
    {R.string.example4, R.string.example5, R.string.example6, R.string.example7}, 
}; 
CharSequence[][] childview = fromRes(resIds);