java - Different Link in context menu depending on ImageView Clicked -
i have activity has crests of different teams, when 1 clicked context menu displayed possibility of opening teams wikipedia page on browser. managed create different context menu depending on imageview have no idea how i'm going pass link. ?
context_menu.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/link" android:title="open wikipedia page" /> </menu>
teams class
public void oncreatecontextmenu(contextmenu menu, view v, contextmenu.contextmenuinfo menuinfo){ super.oncreatecontextmenu(menu,v,menuinfo); menuinflater inflater = getmenuinflater(); switch (v.getid()){ case r.id.atalanta: menu.setheadertitle("atalanta"); inflater.inflate(r.menu.context_menu,menu); break; case r.id.bologna: menu.setheadertitle("bologna"); inflater.inflate(r.menu.context_menu,menu); break; case r.id.cagliari: menu.setheadertitle("cagliari"); inflater.inflate(r.menu.context_menu,menu); break; case r.id.chievo: menu.setheadertitle("chievo"); inflater.inflate(r.menu.context_menu,menu); break; }
if you're able set context menu's header title based on code in switch
block, able set string
variable link. after switch
, can create new intent
, pass link it, start it. of should below:
string link = ""; //... switch (v.getid()) { case r.id.atlanta: menu.setheadertitle("atalanta"); link = "https://whateveryouwant.com" inflater.inflate(r.menu.context_menu,menu); break; //do every case } //... intent = new intent(intent.action_view); i.setdata(uri.parse(link)); startactivity(i);
Comments
Post a Comment