简体   繁体   中英

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. 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.
  2. set the fontsize of textview in listview at your listview;s getview method with textview.setTextSize(int,float);

For accessing a database please check an example here: 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.

Hope this helps!

It's so easy, first you make sure that you can receive textSize from database. 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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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