xamarin.android - Create custom dialog with Grid of buttons -


i trying add custom dialog custom buttons, possible? if so, how can it?

enter image description here

it possible. take @ gridview need create custom adapter load images , titles each of items in grid.

i go this.

create simple class holding information each item in grid. let call griditem.

public class griditem {     public string title { get; set; }     public int imageresourceid { get; set; }     public action clickaction { get; set; } } 

title title under image, imageresoruceid resource drawable id in project, i.e.: resource.drawable.googleplus , clickaction action when item clicked.

now create layout items in grid. grid_item.axml.

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content">     <textview         android:id="@+id/grid_item_title"         android:layout_height="wrap_content"         android:layout_width="fill_parent"         android:layout_margintop="2dp"         android:layout_marginbottom="2dp"         android:layout_alignparentbottom="true"         android:gravity="center_horizontal"         android:layout_centerhorizontal="true" />     <imageview         android:id="@+id/grid_item_image"         android:layout_above="@+id/grid_item_title"         android:layout_height="fill_parent"         android:layout_width="fill_parent" /> </relativelayout> 

now custom adapter, gridadapter.

public class gridadapter : baseadapter<griditem> {     private readonly ilist<griditem> _items;     private readonly context _context;      public gridadapter(context context, ilist<griditem> items)     {         _context = context;         _items = items;     }      public override long getitemid(int position)     {         return position;     }      public override view getview(int position, view convertview, viewgroup parent)     {         var item = _items[position];         var view = convertview;         if (view == null)         {             var inflater = layoutinflater.fromcontext(_context);             view = inflater.inflate(resource.layout.grid_item, parent, false);             view.clickable = true;             view.click += (s, a) => item.clickaction.invoke();         }          var image = view.findviewbyid<imageview>(resource.id.grid_item_image);         var title = view.findviewbyid<textview>(resource.id.grid_item_title);          title.text = item.title;         image.setimageresource(item.imageresourceid);          return view;     }      public override int count     {         { return _items.count; }     }      public override griditem this[int position]     {         { return _items[position]; }     } } 

and layout gridview itself, customgridviewdialog.axml.

<gridview   android:id="@+id/gridview"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:numcolumns="2"   android:verticalspacing="10dp"   android:horizontalspacing="10dp"   android:stretchmode="columnwidth"   android:gravity="center"/> 

then when creating dialog have code this:

var customview = layoutinflater.inflate (resource.layout.customgridviewdialog, null); var items = new list<griditem> {     new griditem     {         title = "google",         itemresourceid = resource.drawable.google,         clickaction = () => { google(); }     },     ... }; (customview.findviewbyid<gridview>(resource.id.gridview)).adapter = new gridadapter(this, items);  var builder = new alertdialog.builder(this); builder.settitle("share"); builder.setview(customview); 

and should it.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -