Sadda Hussain
Sadda Hussain

Reputation: 373

How to get the Title of ActionBar in non-activity class in android

public void onClick(View v) {
   //referenceOfActivity 
  // here is the context, don't know how to use it to get ActionBar title
  Toast.makeText(referenceOfActivity,"Already Liked",Toast.LENGTH_SHORT).show();
}

I want to get the title of action bar within an adapter class. As you can see I have the Context of Activity.

Upvotes: 1

Views: 572

Answers (1)

Montassir Ld
Montassir Ld

Reputation: 561

Cast your activity name to your context. Example;

((MainActivity) referenceOfActivity).getSupportActionBar().getTitle()

Upvotes: 4

Related Questions