【发布时间】:2012-07-06 11:09:38
【问题描述】:
我的库项目中有一个 SettingsActivity,它是 PreferenceActivity 的子类
oncreate 方法如下所示
addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.main);
preference.xml 文件的结构类似于元素 PreferenceScreen -> PreferenceCategory -> Preference 我的main main.xml是这样的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!--Listview will be replaced by preferences -->
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
上面的类SettingsActivity在另一个项目中被子类化,看起来像这样
public class SettingsActivityFree extends SettingsActivity
{
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//...
// layout returned will be null ..
LinearLayout layout = (LinearLayout)findViewById(R.layout.main);
// Add the adView to it
layout.addView(adView);
}
问题是我试图从父类中获取 LinearLayout 以便我可以在其中添加我的东西,但由于某种原因它返回 null ,我在 SettingsActivity 类中有 LinearLyout 的原因是因为我想放一些广告等在首选项的顶部,而无需将广告特定代码放入库项目中
如果我在这里遗漏了什么,请告知,
谢谢
【问题讨论】:
标签: android