2012-11-24 6 views
3

SimpleCursoradapter를 사용하는 응용 프로그램을 만들었습니다.Simplecursoradaptor 내 사용자 정의 텍스트 글꼴

String[] from = new String[] {"title","notes","image"}; 
    int[] to = new int[] { R.id.esodaTextView, R.id.amountTextView, R.id.imageView1}; 
    esodaAdapter = new SimpleCursorAdapter (this, R.layout.recipe_list_item, null, from, to); 

3 개의 데이터를 2 개의 TextView (esodaTextView + amountTextView)와 하나의 imageView에 표시합니다.

질문은 어떻게 사용자 정의 글꼴로 텍스트를 표시 할 수 있도록이 두 TextViews (esodaTextView + amountTextView)에 사용자 정의 글꼴 (자산 폴더에 저장 됨)을 설정할 수 있습니까?

이 목록 항목에 대한 XML 파일입니다

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_margin="10dp" 
android:background="#55eee9e9" > 

<TextView 
android:id="@+id/esodaTextView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:padding="10dp" 
android:textSize="20dp" 
android:textColor="#000000" 
android:minHeight="?android:attr/listPreferredItemHeight" 
android:gravity="center_vertical" /> 

<TextView 
android:id="@+id/amountTextView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/esodaTextView" 
android:gravity="center_vertical" 
android:paddingLeft="10dp" 
android:paddingBottom="5dp" 
android:textSize="12dp" /> 

<ImageView 
android:id="@+id/imageView1" 
android:layout_width="80dp" 
android:layout_height="80dp" 
android:layout_centerVertical="true" 
android:layout_marginRight="10dp" 
android:layout_alignParentRight="true" 
android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

내가 프로그래밍 방식으로 다음 코드를 통해 사용자 정의 글꼴을 설정할 수 있다는 것을 알고 있지만, 나는 그것이 Simplecursoradaptor 내에서 어떻게 사용할 수 있습니까?

TextView txt1 = (TextView) findViewById(R.id.textView1); 
Typeface font = Typeface.createFromAsset(getAssets(), "segoescb.ttf"); 
txt1.setTypeface(font); 

미리 도움을 주셔서 감사합니다.

답변

2

싶은 것은 덮어이다 SimpleCursorAdapter의 ViewBinding : 코드 라인에서

SimpleCursorAdapter.ViewBinder binding=adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() 
    { 
    boolean SetViewValue(View view, Cursor cursor, int columnIndex) 
    { 
     TextView tv=(TextView)view.findViewById(R.id.iesodaTextView) 
     //Do what you want here 
     return true; 
    } 
    }); 
+0

: "텍스트 뷰의 TV = view.findViewById (R.id.iesodaTextView);" 오류가 발생합니다. 형식 불일치 :보기에서 TextView로 변환 할 수 없습니다. –

+1

수정되었으므로'findViewById'의 출력을 형식 변환해야합니다. – PearsonArtPhoto

+1

이제 오류 메시지가 표시되지 않지만 ... 텍스트가 새 글꼴로 표시되지 않습니다 ... "true true"를 추가했습니다. 당신의 코드에서. –