Android 添加到ArrayAdapter里的TEXTview的字体怎么改

katip111 2012-05-14 10:22:11
具体代码:ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,R.layout.list_item1,feed.getAllItems());
布局文件list_item1里有个textview我想改变这TEXTVIEW的字体.
我想这样改变的不过报错了
TextView textall=(TextView)findViewById(R.id.textAll);
typeface=Typeface.createFromAsset(getAssets(),"font/MgOpenCosmeticaBold.ttf");
textall.setTypeface(typeface);
用什么样的方法可以改这个TEXITVIEW的字体??
...全文
474 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
程大治 2014-06-16
  • 打赏
  • 举报
回复
自己写adapter继承baseadapter吧 在getview方法中设置textview的字体
我根号四你 2014-06-16
  • 打赏
  • 举报
回复
重写Arrayadapter 就行了。http://www.eoeandroid.com/blog-576315-1954.html
katip111 2012-05-15
  • 打赏
  • 举报
回复
谢谢你!用这代码不会报错能正常运行,不过字体还是没改成。
程序的list_item1.xml 内容如下:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#0000ff"
android:textStyle="italic"
android:gravity="right"
android:paddingLeft="6dip"

android:minHeight="?android:attr/listPreferredItemHeight"
/>

只有一个TEXTView。麻烦你了,这程序对我很重要,望你帮助
AMinfo 2012-05-15
  • 打赏
  • 举报
回复
那3行代码改一下:

LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater.inflate(R.layout.list_item1, null);
TextView textall=(TextView) v1.findViewById(R.id.textAll);
typeface=Typeface.createFromAsset(getAssets(),"font/MgOpenCosmeticaBold.ttf");
textall.setTypeface(typeface);
katip111 2012-05-15
  • 打赏
  • 举报
回复
没人帮忙吗???
katip111 2012-05-14
  • 打赏
  • 举报
回复
报的是NULL POINTER EXCEPTION

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧