2014-10-09 46 views
-1

是否有可能將myFont設置爲String [],我正在做類似的操作 我想將Font設置爲R.id.txt,但所有值都通過String []傳遞給HashMap無法設置字體setAdapter

optionsMenuList.setAdapter(new SimpleAdapter(getApplicationContext(), 
 
\t \t \t \t array, R.layout.custom_list_row, 
 
\t \t \t \t new String[] { "Name", "Image" }, new int[] { R.id.txt, 
 
\t \t \t \t \t \t R.id.music })); 
 
\t \t ((TextView) findViewById(R.id.txt)).setTypeface(Title);

+0

這裏是什麼題目? \t \t((的TextView)findViewById(R.id.txt))setTypeface(標題)。 標題是字體的實例? – 2014-10-09 07:19:47

+0

Typeface Title = Typeface.createFromAsset(getAssets(), \t \t \t \t「fonts/SegoeRg.ttf」); 感謝名單的回覆.... – 2014-10-09 07:23:32

回答

0

如果UR R.id.txt屬於custom_list_row XML然後

optionsMenuList.setAdapter(new SimpleAdapter(this, array, R.layout.custom_list_row, new String[] {"Name", "Image"}, new int[] {R.id.txt, R.id.music})); 

在烏爾適配器類,getView方法

Context ctx; 
SimpleAdapter(Context ctx, Object[] array, int layout, String[] stringarray, int[] intarray) { 
this.ctx = ctx; 
} 
View v = ctx.getLayoutInflater().inflate(R.layout.custom_list_row, null); 
((TextView) v.findViewById(R.id.txt)).setTypeface(Title); 
+0

哎@Harsha我在「背景」,所以我取出後我從來沒有設置任何一種字體來遇到錯誤txt 所以代碼不起作用。 請幫我 – 2014-10-09 07:33:42

+0

上下文是您的活動類的實例,給一些實例 – 2014-10-09 07:35:13

+0

@Yogesh使用「getApplicationContext()」而不是「背景」 – Sripathi 2014-10-09 08:00:05

0

爲TextView的

創建一個對象
 TextView tv; 
     Typeface typeface = Utils.getTypeFace(activity, <get that font here)>); // get fontstyle from assets if you added 
    tv=(TextView) findViewById(R.id.txt); 
    tv.setTypeface(typeface); 

    public static Typeface getTypeFace(Context context, String type) { 

    if (TextUtils.isEmpty(type)) { 
     return Typeface.createFromAsset(context.getAssets(), fonts/SegoeRg.ttf); 
    } 
+0

嘿@Spark什麼活動在這裏..? 我必須通過哪些活動..? – 2014-10-09 07:41:37

+0

getApplicationContext @YogeshMane如果使用適配器。如果您使用的名稱延伸活動..你可以使用Name.this – Shadow 2014-10-09 07:44:48

+0

我的NullPointerException再次得到.... 我不KW什麼問題.. 問題是電視=(TextView的)findViewById(R.id.txt ); 我通過這些文字爲String []這就是爲什麼我的事情,我得到的NullPointerException – 2014-10-09 07:56:36