0

I have a launcher activity which contains two tabs which corresponds to two separate activities HeatMap and LiveMkt.

As I read somewhere one can not use following statement in child activities:

Window.RequestFeature(WindowFeatures.CustomTitle);

So I tried following....

OnCreate() of Launcher activity contains :

base.OnCreate (bundle);
Window.RequestFeature(WindowFeatures.CustomTitle);
SetContentView(Resource.Layout.TabView);
//Code to create tabs which points to two activities `HeatMap` and `LiveMkt`

OnCreate() of LiveMkt contains :

base.OnCreate (bundle);
SetContentView(Resource.Layout.LiveMkt);
Window.SetFeatureInt(WindowFeatures.CustomTitle,Resource.Layout.TitleBar);
edsearch = (EditText) FindViewById(Resource.Id.edsearch);       
_autoSearchBox = new AutoSearchBox();                       
_autoSearchBox.LoadSearchBox(this,edsearch,lsym);

where AutoSearchBox class has LoadSearchBox() which contains

public void LoadSearchBox(Activity activity,EditText edsearch,ListView lsym)
{
    edsearch.TextChanged+= delegate 
    {//Something
     }
}

But when I debugged this, I get NullPointerException in LoadSearchBox() for edsearch and lsym even though I have these two elements in LiveMkt and passing them to LoadSearchBox().

LiveMkt.xml contains ListView lsym and TitleBar.xml contains EditText edsearch.

StackTrace:

Exception Details : System.NullReferenceException: Object reference not set to an instance of an object

at AutoSearchBox.LoadSearchBox (Android.App.Activity activity, Android.Widget.EditText edsearch, Android.Widget.ListView lsym)

As I'm new to Mono Android, any help appreciated.

GAMA
  • 5,958
  • 14
  • 79
  • 126
  • Let me rephrase. Please post the entire stacktrace. – Arnab Chakraborty Apr 05 '12 at 11:31
  • Apologies for my assumption. I'm just used to seeing larger traces. – Arnab Chakraborty Apr 05 '12 at 11:39
  • Please post your `LiveMkt.xml` – Arnab Chakraborty Apr 05 '12 at 11:49
  • Aah! You see `FindViewById()` is a Activity method and since `LiveMkt.xml` doesn't contain the `EditText` (as per your comment above), it will return null as it will only try to find view with id `edsearch` in `LiveMkt.xml`. What you need is to figure out how to attach eventhandlers to custom window title views (which is not a part of your activity). – Arnab Chakraborty Apr 06 '12 at 01:14
  • I got(and somewhere had an idea) the 1st part u said. But here comes the catch as I'm not able to crack the 2nd part of the suggestion... – GAMA Apr 06 '12 at 04:40
  • I'm not using `Window.RequestFeature(WindowFeatures.CustomTitle);` in `LiveMkt.cs` but in main activity i.e. `TabControl.cs`. In other app, where I had not used `TabActivity`, this code works fine with the inclusion of above statement. – GAMA Apr 06 '12 at 04:56

1 Answers1

0

Are you sure that edsearch is not null? The FindViewById method returns null if it couldn't find the view, so it's possible that's what's happening for you.

Greg Shackles
  • 10,009
  • 2
  • 29
  • 35
  • It is null after the statement `edsearch = (EditText) FindViewById(Resource.Id.edsearch);` in `OnCreate()` of `LiveMkt`. But I'm not getting why it is null even though I have a `TitleBar.xml` and `edsearch` within that.. – GAMA Apr 05 '12 at 11:38