i have gridview , adapter called myadapter. button in each grid not showing dialog box should (myadapter.java). here code, not sure missing here:
myadapter.java
public class myadapter extends baseadapter { context context; arraylist<players> playerlist; private static layoutinflater inflater = null; button btnrolereveal; public myadapter(context context, arraylist<players> playerlist){ this.context = context; this.playerlist = playerlist; inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public int getcount() { return playerlist.size(); } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) convertview = inflater.inflate(layout_grid_item, null); final button button = (button) convertview.findviewbyid(r.id.btnrolereveal); textview idtextview = (textview) convertview.findviewbyid(r.id.tv_player_id); textview nametextview = (textview) convertview.findviewbyid(r.id.tv_player_name); final textview roletextview = (textview) convertview.findviewbyid(r.id.tv_player_role); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { new alertdialog.builder(context) .settitle("test") .setmessage("test"); } }); players p = new players(); p = playerlist.get(position); idtextview.settext("id: " + string.valueof(p.getid())); nametextview.settext("name: " + string.valueof(p.getname())); roletextview.settext("role: " + string.valueof(p.getrole())); return convertview; } }
rolesfragment.java
public class rolesfragment extends fragment implements view.onclicklistener { gridview gridview; arraylist<players> playerslist; myadapter adapter; button role; public rolesfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_viewroles, container, false); gridview = (gridview) view.findviewbyid(r.id.gv_players); role = (button) view.findviewbyid(r.id.btnrolereveal); databasehelper databasehelper = new databasehelper(getactivity()); playerslist = new arraylist<players>(); playerslist = databasehelper.getplayers(); adapter = new myadapter(getactivity(), playerslist); gridview.setadapter(adapter); return view; } @override public void onclick(view v) { } }
you're missing show() call on dialog:
new alertdialog.builder(context) .settitle("test") .setmessage("test") .show();
Comments
Post a Comment