I have a SettingsActivity which is a subclass of PreferenceActivity in my library project
The oncreate method looks like this
addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.main);
The preference.xml file has structure like element PreferenceScreen -> PreferenceCategory -> Preference
My main main.xml Looks like this
<?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>
The above class SettingsActivity is subclassed in another project and Looks like this
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);
}
The problem is I am trying to get LinearLayout from the parent class so that I can add my stuff in it, but for some reason it returns null , the reason I have LinearLyout in the SettingsActivity class is because I want to put some ads etc at the top of preferences and without putting ad specific code in the Library project
Please advise If I am missing something here,
Thanks
First you need to give your LinearLayout an
idusingandroid:id="@+id/whatever". Then you can search for it usingfindViewById(R.id.whatever).