问题:有一个List页面包含多个item,点击其中的item后,进入另外一个List页面,你会如何实现该功能?如果后期又要添加一些item,又如何实现?
常规的方法是实现一个ListActivity,然后编写它的适配器。对于item点击事件,需要另外编写一个ListActivity。
如果后期要添加ListActivity的item,还要回头扒代码,一个一个的修改。
通过http://viewpagerindicator.com/的样例代码学习,将会学会如何动态管理List的选项。
它是利用PackageManager,通过Manifest的intent-filter标签来管理ListActivity的item,通过activity标签的label和name熟悉来识别Item是属于谁的。
实现流程如下:
// Return PackageManager instance to find global package information.
PackageManager pm = getPackageManager();
// Retrieve all activities that can be performed for the given intent.
List<ResolveInfo> list = pm.queryIntentActivities(customIntent, 0);
ResolveInfo info = list.get(0);
// Retrieve the current textual label associated with this resolution.
CharSequence labelSeq = info.loadLabel(pm);