user3172335
user3172335

Reputation: 3

Setting Menu Title from Custom ListView Adapter

I would like to know if there is any way of changing the MenuItem title from a ListView's button on click listener. The ListView onClickListener is in a custom adapter.

I was hoping that I could just do something like this:

Menu menu = (Menu) context.getMenu();

MenuItem quantity = (MenuItem) menu.findItem(R.id.action_cart);
quantity.setTitle("10");

but to no avail.

Any idea's?

Upvotes: 0

Views: 568

Answers (1)

Ketan Ahir
Ketan Ahir

Reputation: 6728

define setMenuItem() in activity and call it from adapter.

public static void setMenuItem(String title){

   Menu menu = (Menu) context.getMenu();

   MenuItem quantity = (MenuItem) menu.findItem(R.id.action_cart);
   quantity.setTitle(title);

 }

now call this method in adapter as YourActivity.setMenuItem("Your Title");

Upvotes: 1

Related Questions