如果您想要相同的外观/行为,您应该保持简单的PreferenceActivity
实现,并preference items
从代码动态地将新的添加到“列表”中(最终使用自定义渲染器)。
这种显示的基本实现是:
/**
* This variable stands for the items with which you want to populate the list
*/
final HashMap<String, String> networks = new HashMap<String, String>();
final PreferenceCategory cat = new PreferenceCategory(getApplicationContext());
cat.setTitle(R.string.wifinetworks); // holding "Wi-fi networks"
for (final String networkTitle : networks.keySet())
{
final Preference pref = new Preference(getApplicationContext());
pref.setTitle(networkTitle);
pref.setSummary(networks.get(networkTitle));
cat.addPreference(pref);
}
编辑:要将自定义组件添加到现有的PreferenceActivity
,您应该尝试该addContentView
方法。从内部onCreate
:
final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
addContentView(buttonBar, params);