Creating with visual studio a skeleton app with tabbed views. One tab is for settings but having trouble using preferences api. I get this error :
android.view.View cannot be cast to android.view.ViewGroup
Here's the code:
//***********************
//class for settings tab
//***********************
[Activity(Label = "Settings")]
[MetaData(PreferenceManager.MetadataKeyPreferences, Resource = "@drawable/preferences")]
public class Settings : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View vg = new View(this);
TextView textview = new TextView(vg.Context);
textview.Text = "This is the Settings Tab";
SetContentView(vg);
textview.Id = TextView.GenerateViewId();
vg.Id = View.GenerateViewId();
FragmentTransaction fragmentTx = this.FragmentManager.BeginTransaction();
SettingsFragment cfg = new SettingsFragment();
fragmentTx.Add(vg.Id, cfg);
// Commit the transaction.
fragmentTx.Commit();
}
}
public class SettingsFragment : PreferenceFragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AddPreferencesFromResource(Resource.Xml.preferences);
/*var intent = new Intent(this.Activity, typeof(Settings));
AddPreferencesFromIntent(intent);*/
}
}