歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Android裡在程序中修改listView裡的內容

Android裡在程序中修改listView裡的內容

日期:2017/2/28 16:32:02   编辑:Linux教程

在Android的列表中動態加載列表項需要對adapter裡的源容器進行更新修改後再調用adapter.notifyViewChanaged()方法刷新當前listView.比如說:

adapter = new SimpleAdapter(this, tempList,

android.R.layout.simple_list_item_2, new String[] { Item.TITLE,Item.PUBDATE },

new int[]{ android.R.id.text1 , android.R.id.text2});

listView.setAdapter(adapter);

對adapter構造裡的tempList進行修改後再調用adapter.notifyViewChanaged()就可以實現動態修改listView的內容了.如果想動態修改listView裡字體的大小和相關布局的話,程序中驗證adapter一旦構造後就不能再修改布局文件.可以通過重新構造adapter加入不同的布局文件來實現動態修改listView字體大小的目的.這樣的缺點是需要多個描述listView列表布局的布局文件.好處是可以作為主題修改功能來用.

Copyright © Linux教程網 All Rights Reserved