2

I have setup a new android project with the default navigation drawer implemented for me. I created a custom NavagationDrawerAdapter which will return a more complex RelativeLayout for the first item of the navigation drawer. In this RelativeLayout, I have some buttons.

I have assigned the onclick attribute in the xml for these buttons to be addPhoto.

I then declared addPhoto thus in the MainActivity:

public void addPhoto(View view) {
    Intent intent = new Intent(this, AddPhotoActivity.class);
    startActivity(intent);
}

As I understand it, the navigation drawer is only a fragment and it resides in the MainActivity?

When I run the app it gives:

Could not find a method addPhoto(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.ImageView with id 'imageView3'

It looks like it is using the activity ContextThemeWrapper or something...

How should I handle the onclick for an item in navdrawer?

Any help would be appreciated.

Jed Fox
  • 2,979
  • 5
  • 28
  • 38
l3utterfly
  • 2,106
  • 4
  • 32
  • 58
  • Do you have the addPhoto(View view) method in the context that you are referring your ImageView? I mean - are you referring it from a fragment but the click handler is in an activity or something like that? – ucsunil May 21 '14 at 16:42
  • I'm not sure what you mean by referring. The only place (apart from the declaration) I have referred to this function is in the layout xml file. – l3utterfly May 21 '14 at 17:57
  • Post your layout xml and MainActivity code – tim.paetz Nov 06 '17 at 17:21

0 Answers0