简体   繁体   English

如何根据Android中的数据库值动态设置列表视图中所有项目的文本大小?

[英]How to dynamically set text size of all items in a list view based on database value in Android?

I'm trying to allow the user to set the font size in an app that uses ListViews. 我试图允许用户在使用ListViews的应用程序中设置字体大小。 How do I get the font-size from a database and use it to set the size of text in a listview? 如何从数据库中获取字体大小并使用它来设置列表视图中的文本大小?

Edit: examples would be nice :) 编辑:例子会很好:)

  1. get the fontsize from database using select query. 使用select查询从数据库中获取fontsize。
  2. set the fontsize of textview in listview at your listview;s getview method with textview.setTextSize(int,float); 在listview中设置listview中textview的fontsize;使用textview.setTextSize(int,float)设置getview方法;

For accessing a database please check an example here: http://www.devx.com/wireless/Article/40842/1954 要访问数据库,请在此处查看示例: http//www.devx.com/wireless/Article/40842/1954

In order to change the text size of the textview of a listview, you should set this font size in the getView() of the listview's adapter. 要更改列表视图的textview的文本大小,应在listview的适配器的getView()中设置此字体大小。

Hope this helps! 希望这可以帮助!

It's so easy, first you make sure that you can receive textSize from database. 这很容易, 首先确保您可以从数据库接收textSize。 second you must find the text from listview item,in method OnItemClick() you can get the view which clicked, and then use View.findviewbyid() to find out which view you want set the textsize,then use getText() method to receive text what you want to change, in the end you maybe call method notifyDataSetChanged() . 第二,你必须从listview项找到文本,在方法OnItemClick()中你可以得到点击的视图,然后使用View.findviewbyid()找出你想要设置文本大小的视图,然后使用getText()方法接收文本你要改变什么,最后你可能调用方法notifyDataSetChanged()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM