Confuser
Confuser

Reputation: 53

How to display data in custom font in listview in listadapter?

I have a code here, I want to change font in listview and display it,in listadapter. however, it doesn't help but only show a default number rather than real data. Is this the correct way of change font of my data?

       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;
                }

Upvotes: 0

Views: 615

Answers (3)

Akash Moradiya
Akash Moradiya

Reputation: 3322

try like this may help you,

 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;
                }

Upvotes: 0

Ando Masahashi
Ando Masahashi

Reputation: 3122

rename your font file name

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

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

use _ where space is there

Upvotes: 0

M D
M D

Reputation: 47817

Set text to your TextView like

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

tv.setText(""+pos);

do the same for other TextViews

Upvotes: 2

Related Questions