2013-10-21 3 views
0

현재 액티비티의 모든 textviews 유형을 변경하면 Textview Text를 제외하고 모두 변경됩니다.Listviews 하위 Textviews 서체 오류

하지만 난이 목록보기의 대해서 itemClick 리스너에서 같은 함수를 호출 할 때 글꼴이 변경 내가 그것을 클릭 할 필요없이 목록보기의 글꼴을 설정하는 방법

 ((TextView) view).setTypeface(CreateTypeface); 

?

 final View rootView = findViewById(android.R.id.content); 


public void applyCustomFont(ViewGroup list) 
    { 


     for (int i = 0; i < list.getChildCount(); i++) { 
      View view = list.getChildAt(i); 

      if (view instanceof ViewGroup) 
      { 
       applyCustomFont((ViewGroup) view); 
      } else if (view instanceof TextView) 
      { 
       ((TextView) view).setTypeface(CreateTypeface); 



     } 
     } 
    } 



    lvfonts.setAdapter(new ArrayAdapter<String> (FontMUI.this,android.R.layout.simple_list_item_1, list)); 

    lvfonts.setOnItemClickListener(new OnItemClickListener() 
    { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) 
        { 
        applyCustomFont((ViewGroup)rootView); 
         } 
         } 
+0

귀하의 질문은 clear..My 이해가가 adpater 클래스의 getView에서 서체를 설정되어 있지 않으며 .. – Subburaj

+0

@Subburaj 내가 사용하지 않은의 getView 방법 난 당신이 전화 목록보기의 클릭 부분에서 내 코드 검사 –

+0

를 업데이트 "Customfont()"method.then 그러면 목록보기 항목을 클릭 할 때만 호출되고 글꼴은 바뀝니다. 이것은 코드의 출력입니다 .Whats your questions ?? – Subburaj

답변

1

사용 목록보기는 목록보기의 차일이리스트 뷰 자체를 통해 액세스 할 필요가 직접 액세스 할 수없는 것입니다 텍스트 뷰의 서브 클래스가 아니기 때문에리스트 뷰의 서체를 설정하려면이 트릭 .

lvfonts.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       applyCustomFont((ViewGroup)rootView); 
       // or call you function to change the Typeface from here 
      } 
      }, 10); 
+0

부탁드립니다. –

1

ListView를 채우는 데 사용하는 사용자 지정 어댑터를 만들어야합니다. 해당 사용자 지정 어댑터에서 getView() 메서드를 재정의해야 View에 변경 내용을 적용하여 사용자에게 표시 할 수 있습니다. 이 같은

뭔가 :

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    if (convertView == null) { 
     convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); 
     ((TextView) convertView).setTypeface(CreateTypeface); 
    } 

    setupTextForPosition(convertView, position); 
}