0

I'm trying to set up a custom actionbar mimicking the Google calendar actionbar based on Simon Jackson's answer to an SO question here.

However, I'm struggling with 'mContext' as I don't know what context it is referring to.

There are 2 instances of mContext, 1 when inflating the View and 2 when instantiating the actionbar. I've tried both the application context and inflater context but although each works for one mContext instance, neither works for both.

In the context of this code fragment, what is mContext?

I'm developing using Android Studio and API 22.

Community
  • 1
  • 1
Doug Conran
  • 437
  • 1
  • 5
  • 17

2 Answers2

1

mContext would be referencing the:

getApplicationContext()

call from the Activity

Lucas Crawford
  • 3,078
  • 2
  • 14
  • 25
  • Thanks. The reason it wasn't working for the actionbar is because I'd imported android.app,actionbar rather than android.support.v7.Actionbar and android.support.v7..app.AppCompatActivity. – Doug Conran Aug 11 '15 at 18:43
  • No problem :) right, those auto-imports get you sometimes with the v7 vs v7.appcompat versions – Lucas Crawford Aug 11 '15 at 18:49
0

Add this before you call onCreate():

Context mContext;

Or preferably as suggested above,replace mContext with getApplicationContext()

Steve Kamau
  • 2,755
  • 10
  • 42
  • 73