我使用偏好标题使用偏好活动。
加载首选项活动时,会动态创建片段。我没有片段ID。 有什么方法可以抓住片段实例吗?
以下是我如何从设置活动加载标题并设置列表活动。
@Override
public void onBuildHeaders(List<Header> target)
{
// Called when the settings screen is up for the first time
// we load the headers from our xml description
loadHeadersFromResource(R.xml.preference_headers, target);
headers= target;
}
@Override
public void setListAdapter(ListAdapter adapter)
{
int i, count;
if (headers== null) {
headers= new ArrayList<Header>();
// When the saved state provides the list of headers,
// onBuildHeaders is not called
// so we build it from the adapter given, then use our own adapter
count = adapter.getCount();
for (i = 0; i < count; ++i) {
headers.add((Header) adapter.getItem(i));
}
}
settingsAdapter = new SettingsAdapter(this, mHeaders);
super.setListAdapter(settingsAdapter);
}
干杯, Saurav