Simplecursoradaptor 内的自定义文本字体

2024-02-24

我制作了一个使用 SimpleCursoradapter 的应用程序。

    String[] from = new String[] {"title","notes","image"};
    int[] to = new int[] { R.id.esodaTextView, R.id.amountTextView, R.id.imageView1}; 
    esodaAdapter = new SimpleCursorAdapter (this, R.layout.recipe_list_item, null, from, to);

正如您所看到的,我在 2 个 TextView(esoda TextView + amount TextView)和一个 imageView 上显示了三个数据。

问题是我如何为这 2 个 TextView(esodaTextView + amountTextView)设置自定义字体(保存在资产文件夹中),以便我可以使用自定义字体显示文本。

这是列表项的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:background="#55eee9e9" >

<TextView 
android:id="@+id/esodaTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20dp"
android:textColor="#000000"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" />

<TextView
android:id="@+id/amountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/esodaTextView"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingBottom="5dp"
android:textSize="12dp" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />

</RelativeLayout>

我知道我可以通过以下代码以编程方式设置自定义字体,但如何在 Simplecursoradaptor 中使用它?

 TextView txt1 = (TextView) findViewById(R.id.textView1);  
 Typeface font = Typeface.createFromAsset(getAssets(), "segoescb.ttf");  
 txt1.setTypeface(font);

提前谢谢你的帮助。


你想要做的是覆盖 SimpleCursorAdapter视图绑定 http://developer.android.com/reference/android/widget/SimpleCursorAdapter.ViewBinder.html:

SimpleCursorAdapter.ViewBinder binding=adapter.setViewBinder( new SimpleCursorAdapter.ViewBinder()
  {
    boolean SetViewValue(View view, Cursor cursor, int columnIndex)
    {
      TextView tv=(TextView)view.findViewById(R.id.iesodaTextView)
      //Do what you want here
      return true;
    }
  });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Simplecursoradaptor 内的自定义文本字体 的相关文章

随机推荐

  • Java中包和目录的区别

    In a Java项目 是否保留所有 java同一文件夹中的文件意味着它们位于同一包中 有什么区别与将所有项目文件保存在一个文件夹中相比 为我们的项目制作一个包 这个线程 https stackoverflow com questions
  • 在 Linux 上使用 bfd.h 编译错误

    我是 Linux 编程新手 正在尝试使用 BFD 库 这是我正在尝试编译的当前代码 include
  • MySQL 中保护列,不允许更新,仅允许在 NULL 时插入

    我想保护日期列中的现有日期不被覆盖 因此 不允许更新日期列 仅当现有字段值为 NULL 日期列默认为 NULL 时才允许插入 是triggers http dev mysql com doc refman 5 0 en triggers h
  • 有没有办法查看 Sql Server 2005 中最近的昂贵查询?

    我最近发现了活动监视器SQL Server 2008 我知道 呃 对吧 最近昂贵的查询 选项卡对我帮助很大 现在我正在尝试调试一个客户端中数据库的过度使用 但是那里的服务器SQL Server 2005 那里有一个活动监视器 但没有 最近昂
  • 为什么四元数有四个变量?

    Unity 引擎的官方文档不包含此内容 而且我的数学 物理研究还不够深入 还没有遇到过四元数 但我知道它与旋转有关 我不明白的是为什么四元数有四个变量 w x y z 而Unity中只有三个旋转轴 四元数基本上是 3D 空间中的一个轴 具有
  • 比较python中的LBP

    我生成了这样的纹理图像 我必须比较两个纹理 我使用了直方图比较方法 image file output ori png img bgr cv2 imread image file height width channel img bgr s
  • 如何使用已打开并使用登录凭据登录的浏览器

    有没有一种方法可以让使用 selenium 的 python 程序的不同运行保持我已打开并使用凭据登录的浏览器 在以后的运行中打开并使用 我正在调试一段代码 每次我需要使用我的凭据登录时在浏览器上 目前 每次我停止代码时 网络浏览器都会关闭
  • 在 Android 中使用已弃用的 AbsoluteLayout 类?

    The 绝对布局 http developer android com reference android widget AbsoluteLayout html类已被弃用 但仍然可以用代码编写它并且它可以工作 如果我使用这个类会有什么问题吗
  • 如何搜索 UITableView

    是的 我知道关于这个主题大约有十亿个问题 但它们似乎都链接到有关实现 UISearchBar 或 Apple 文档的相同旧博客文章 我想知道的是 是否有适当的教程来实现 UISearchDisplayController 类来搜索数组 字典
  • 本地数据库,我需要一些例子

    我正在制作一个将在多台计算机上安装和运行的应用程序 我的目标是制作一个与该应用程序一起安装的空本地数据库文件 当用户使用该应用程序时 他的数据库将填充来自该应用程序的数据 您能给我提供以下示例吗 我需要做什么才能让我的应用程序连接到其本地数
  • 路径别名自动导入错误

    当从 Angular 9 应用程序中提供路径别名的文件夹自动导入服务 组件时 我遇到了奇怪的问题 这些是我在中定义的别名tsconfig json paths core app core shared app shared state ap
  • 在嵌入式linux中使用mono作为硬件

    我正在一家公司实习做研究 我在使用 Mono Net 平台的跨平台实现 时遇到一些问题 我的公司设计硬件和软件 我对使用嵌入式linux的了解非常有限 我实习的公司非常注重 NET 但是 Mono 的新发展 他们问自己是否可以将 Linux
  • 错误处理理论?

    大多数有关错误处理的建议都归结为一些提示和技巧 请参阅这个帖子 https stackoverflow com questions 231128 c error handling good sources of example code例如
  • 如何为 android studio 创建一个名为 Kotlin 的新测试文件夹

    Android Studio 3 1 Canary 4 Build AI 171 4444016 built on November 10 2017 JRE 1 8 0 152 release 1012 b01 amd64 JVM Open
  • 如何从Python中的self方法获取self对象名称

    我正在尝试找到一种方法来自动打印对象引用名称print object更具体 假设我有一堂课 class A def init self self cards def str self return a string representati
  • 将 CA 签名的 JKS 密钥库转换为 PEM

    我有一个带有 CA 签名证书的 JKS 密钥库 我需要将其导出为 PEM 格式才能与 nginx 一起使用 我需要以包含整个链的方式进行操作 以便我的客户可以验证签名 如果我做类似的事情 keytool exportcert keystor
  • pip 安装后没有名为 imutils.perspective 的模块

    我正在尝试遵循本教程 该教程需要imtools 看起来我已经安装了这个包 但Python编译器找不到它 这里发生了什么 教程 http www pyimagesearch com 2016 10 03 bubble sheet multip
  • 带 xcframework 的 Flutter 插件仅适用于不在 ios 模拟器中的设备

    我创建了一个颤振插件 通过在 Flutter 中运行示例应用程序 我收到此错误 Error Swift Compiler Error Xcode No such module AusweisApp2 这是我的文件夹结构 podspec 文件
  • 如何处理移动设备发送的图像?

    我的一位同事正在开发一款 iPhone 应用程序 该应用程序将允许用户通过我的 API 在我的网站上发布图像 我正在构建 API 的一部分 用于接受和处理图像 移动开发人员发送的标头如下 Content Disposition form d
  • Simplecursoradaptor 内的自定义文本字体

    我制作了一个使用 SimpleCursoradapter 的应用程序 String from new String title notes image int to new int R id esodaTextView R id amoun