2014-11-03 35 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

相关问题