我开发了一个Andriod RSS阅读器应用程序.我使用自定义列表视图列出RSS标题及其图像.现在我想更改RSS标题的字体.如何设置字体到我的标题textview?
这是我的适配器类,我在其中设置标题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; } }
解决方法
你可以用这个,
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,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,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 = 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; } }