本文介绍了如何设置在Android的字样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Andriod的RSS阅读器app.I已经使用自定义列表视图中列出的RSS标题及其images.Now我想改变RSS titles.How的字体可以我设置字体为我的头衔的TextView?

下面是我的适配器类中,我设置标题的TextView。

Adapter.java

 公共类InternationalAdapter扩展了BaseAdapter {

    私人活动的活动;
    私人的ArrayList< HashMap的<字符串,字符串>>数据;
    私有静态LayoutInflater吹气= NULL;
    公共ImageLoader的ImageLoader的;

    公共InternationalAdapter(活动一,ArrayList的< HashMap的<字符串,字符串>> D){
        活性= A;
        数据= D;
        充气=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ImageLoader的=新ImageLoader的(activity.getApplicationContext());
    }

    公众诠释getCount将(){
        返回data.size();
    }

    公共对象的getItem(INT位置){
        返回的位置;
    }

    众长getItemId(INT位置){
        返回的位置;
    }

    公共查看getView(INT位置,查看convertView,ViewGroup中父){
        查看VI = convertView;
        如果(convertView == NULL)


            VI = inflater.inflate(R.layout.list_row,NULL);




        TextView的标题=(TextView中)vi.findViewById(R.id.title); //对于这个TextView的我想设置字体。
        TextView的日期=(TextView中)vi.findViewById(R.id.artist);

        ImageView的thumb_image =(ImageView的)vi.findViewById(R.id.list_image);

        HashMap的<字符串,字符串>新闻=新的HashMap<字符串,字符串>();
        新闻= data.get(位置);

        //设置列表视图中的所有值
        title.setText(International.Title [位置]);
        date.setText(International.Date [位置]);
        imageLoader.DisplayImage(International.image [位置],thumb_image);
        返回六;
    }
}
 

解决方案

您可以使用此功能,

 公共类InternationalAdapter扩展了BaseAdapter {

            私人活动的活动;
            私人的ArrayList< HashMap的<字符串,字符串>>数据;
            私有静态LayoutInflater吹气= NULL;
            公共ImageLoader的ImageLoader的;

            公共InternationalAdapter(活动一,ArrayList的< HashMap的<字符串,字符串>> D){
                活性= A;
                数据= D;
                充气=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                ImageLoader的=新ImageLoader的(activity.getApplicationContext());
            }

            公众诠释getCount将(){
                返回data.size();
            }

            公共对象的getItem(INT位置){
                返回的位置;
            }

            众长getItemId(INT位置){
                返回的位置;
            }

            公共查看getView(INT位置,查看convertView,ViewGroup中父){
                查看VI = convertView;
                如果(convertView == NULL)


                    VI = inflater.inflate(R.layout.list_row,NULL);




                TextView的标题=(TextView中)vi.findViewById(R.id.title); //对于这个TextView的我想设置字体。
                TextView的日期=(TextView中)vi.findViewById(R.id.artist);
//此处添加
        字样字体= Typeface.createFromAsset(
        activity.getAssets(),
        字体/ androidnation.ttf);
    标题.setTypeface(字体);

                ImageView的thumb_image =(ImageView的)vi.findViewById(R.id.list_image);

                HashMap的<字符串,字符串>新闻=新的HashMap<字符串,字符串>();
                新闻= data.get(位置);

                //设置列表视图中的所有值
                title.setText(International.Title [位置]);
                date.setText(International.Date [位置]);
                imageLoader.DisplayImage(International.image [位置],thumb_image);
                返回六;
            }
        }
 

I have developed an Andriod RSS reader app.I have used custom listview to list RSS titles and its images.Now I want to change the font of RSS titles.How can I set typeface to my title textview?

Here is my adapter class in which I am setting the title Textview.

Adapter.java

public class InternationalAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

    public InternationalAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)


            vi = inflater.inflate(R.layout.list_row, null);




        TextView title = (TextView)vi.findViewById(R.id.title); // For this Textview I want to set Typeface.
        TextView date = (TextView)vi.findViewById(R.id.artist);

        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);

        HashMap<String, String> news = new HashMap<String, String>();
        news = data.get(position);

        // Setting all values in listview
        title.setText(International.Title[position]);
        date.setText(International.Date[position]);
        imageLoader.DisplayImage(International.image[position], thumb_image);
        return vi;
    }
}
解决方案

You can use this,

        public class InternationalAdapter extends BaseAdapter {

            private Activity activity;
            private ArrayList<HashMap<String, String>> data;
            private static LayoutInflater inflater=null;
            public ImageLoader imageLoader; 

            public InternationalAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
                activity = a;
                data=d;
                inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                imageLoader=new ImageLoader(activity.getApplicationContext());
            }

            public int getCount() {
                return data.size();
            }

            public Object getItem(int position) {
                return position;
            }

            public long getItemId(int position) {
                return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
                View vi=convertView;
                if(convertView==null)


                    vi = inflater.inflate(R.layout.list_row, null);




                TextView title = (TextView)vi.findViewById(R.id.title); // For this Textview I want to set Typeface.
                TextView date = (TextView)vi.findViewById(R.id.artist);
//Added Here
        Typeface font = Typeface.createFromAsset(
        activity.getAssets(), 
        "fonts/androidnation.ttf");
    title .setTypeface(font);

                ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);

                HashMap<String, String> news = new HashMap<String, String>();
                news = data.get(position);

                // Setting all values in listview
                title.setText(International.Title[position]);
                date.setText(International.Date[position]);
                imageLoader.DisplayImage(International.image[position], thumb_image);
                return vi;
            }
        }

这篇关于如何设置在Android的字样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:38