Как отображать данные в пользовательском шрифте в списке в listadapter?

У меня есть код, я хочу изменить шрифт в списке и отобразить его в listadapter. однако это не помогает, а только показывает номер по умолчанию, а не реальные данные. Это правильный способ изменить шрифт моих данных?

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

person Confuser    schedule 03.11.2014    source источник
comment
Проверьте: stackoverflow.com/questions/26505109/   -  person Haresh Chhelana    schedule 03.11.2014
comment
На самом деле название вашего вопроса не связано с описанием вашего вопроса.   -  person M D    schedule 03.11.2014


Ответы (3)


попробуйте, как это может помочь вам,

 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;
                }
person Akash Moradiya    schedule 03.11.2014
comment
Привет, @moradiya akash, я не очень понимаю эту строку tv2.setText(productsList.get(position).get()); , какая позиция? Где я должен объявить об этом? - person Confuser; 03.11.2014
comment
Можете ли вы сказать мне тип данных productsList? - person Akash Moradiya; 03.11.2014
comment
Я объявляю как этот ArrayList‹HashMap‹String, String›› productsList; @Морадия Акаш - person Confuser; 03.11.2014
comment
вы должны поместить туда ключ hashmap - person Akash Moradiya; 03.11.2014
comment
точно так же, как TAG_DESCRIPTION, который вы использовали - person Akash Moradiya; 03.11.2014
comment
Да, у него ошибка, я вставил тег, и там есть ошибка в значении. - person Confuser; 03.11.2014
comment
В конце концов, ошибки нет, но когда я запускаю приложения, они вылетают. - person Confuser; 03.11.2014

Установите текст на свой TextView лайк

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

tv.setText(""+pos);

сделать то же самое для других TextViews

person M D    schedule 03.11.2014
comment
Привет, я новичок в Android, не могли бы вы рассказать мне, как получить данные из массива в соответствии с позицией? - person Confuser; 03.11.2014
comment
@M D, я запускаю его, но, к сожалению, он вылетает. - person Confuser; 03.11.2014

переименуйте имя файла шрифта

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");

используйте _ там, где есть место

person Ando Masahashi    schedule 03.11.2014