2014-11-03 37 views
0

我在這裏有一個代碼,我想在listview中更改字體並將其顯示在listadapter中。然而,它並沒有幫助,只是顯示一個默認的數字而不是實際的數據。這是改變我的數據字體的正確方法嗎?如何在listadapter的listview中顯示自定義字體中的數據?

 ListAdapter adapter = new SimpleAdapter(
         AllProductsActivity3.this, productsList, 
         R.layout.list_item3, new String[] { TAG_PID, 
           TAG_NAME, TAG_PRICE, TAG_DESCRIPTION}, 
         new int[] { R.id.pid, R.id.username,R.id.p_title, R.id.approval }){ 

       @Override 
       public View getView(int pos, View convertView, ViewGroup parent){ 
        View v = convertView; 
        if(v== null){ 
         LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         v=vi.inflate(R.layout.list_item3, null); 
        } 
        TextView tv = (TextView)v.findViewById(R.id.username); 
        Typeface custom_fontG = Typeface.createFromAsset(getAssets(), 
           "fonts/orange juice 2.0.ttf"); 
           tv.setTypeface(custom_fontG); 


        TextView tv2 = (TextView)v.findViewById(R.id.p_title); 
        Typeface custom_fontH = Typeface.createFromAsset(getAssets(), 
           "fonts/orange juice 2.0.ttf"); 
           tv2.setTypeface(custom_fontH); 

        TextView tv3 = (TextView)v.findViewById(R.id.approval); 
           Typeface custom_fontI = Typeface.createFromAsset(getAssets(), 
              "fonts/orange juice 2.0.ttf"); 
              tv3.setTypeface(custom_fontI); 
        return v; 
       } 
+0

檢查:http://stackoverflow.com/questions/26505109/how-to-use-custom-font-in-custom-baseadapter/ 26505473#26505473 – 2014-11-03 12:39:49

+0

其實您的問題標題與您的問題描述無關。 – 2014-11-03 12:47:54

回答

0

嘗試這樣可以幫助你,

ListAdapter adapter = new SimpleAdapter(
         AllProductsActivity3.this, productsList, 
         R.layout.list_item3, new String[] { TAG_PID, 
           TAG_NAME, TAG_PRICE, TAG_DESCRIPTION}, 
         new int[] { R.id.pid, R.id.username,R.id.p_title, R.id.approval }){ 

       @Override 
       public View getView(int pos, View convertView, ViewGroup parent){ 
        View v = convertView; 
        if(v== null){ 
         LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         v=vi.inflate(R.layout.list_item3, null); 
        } 

        HashMap<String,String> value = productsList.get(pos); 

        TextView tv = (TextView)v.findViewById(R.id.username); 
        Typeface custom_fontG = Typeface.createFromAsset(getAssets(), 
           "fonts/orange juice 2.0.ttf"); 
           tv.setTypeface(custom_fontG); 
        tv.setText(value.get(//put key to get value from hashmap)); 


        TextView tv2 = (TextView)v.findViewById(R.id.p_title); 
        Typeface custom_fontH = Typeface.createFromAsset(getAssets(), 
           "fonts/orange juice 2.0.ttf"); 
           tv2.setTypeface(custom_fontH); 
        tv2.setText(value.get(//put key to get value from hashmap)); 

        TextView tv3 = (TextView)v.findViewById(R.id.approval); 
           Typeface custom_fontI = Typeface.createFromAsset(getAssets(), 
              "fonts/orange juice 2.0.ttf"); 
              tv3.setTypeface(custom_fontI); 
        tv3.setText(value.get(//put key to get value from hashmap)); 
        return v; 
       } 
+0

嗨,@moradiya akash,我真的不明白這行tv2.setText(productsList.get(position).get(「」)); ,這個職位是什麼?我可以宣佈嗎? – Confuser 2014-11-03 12:47:44

+0

你能告訴我productsList的數據類型嗎? – 2014-11-03 12:48:33

+0

我聲明爲這個ArrayList > productsList; @Moradiya Akash – Confuser 2014-11-03 12:53:11

2

集文字到您TextView

tv.setText(fetch data from arrayList as per Position); 

tv.setText(""+pos); 

做同樣的其他TextViews

+0

嗨,我是android的新手,你能告訴我如何從arraylist中獲取數據嗎? – Confuser 2014-11-03 13:37:57

+0

@M D,我讓它運行,但不幸的是,它崩潰了。 – Confuser 2014-11-03 13:58:12

0

重命名字體文件名

Typeface custom_fontG = Typeface.createFromAsset(getAssets(), 
          "fonts/orange juice 2.0.ttf"); 

Typeface custom_fontG = Typeface.createFromAsset(getAssets(), "fonts/orange_juice_2.0.ttf");

使用_在空間有

+0

它沒有幫助。 – Confuser 2014-11-03 13:47:20

相關問題