android - Change row height in gridview -


i'm new android development , making first app, it's wordsearch app project , using gridview display letters search. able change width of cells in grid using layout xml's, can't change height , @ moment it's far much.

i tried google answers on how found said overriding getview in custom arrayadapter, , don't follow how or how set height fixed amount when doing it. have row width set 25dp in layout files , want change height match that, can't seem find easy follow way of doing online.

cheers in advance if can help.

edit: here fill grids:

//fill gridview puzzle input array puzzle class arrayadapter<string> gridadapter = new arrayadapter<string>(c, r.layout.cell_layout, todayspuzzle.puzzleinputarray); wordsearchgrid.setadapter(gridadapter);  //fill listview searchwords array puzzle class arrayadapter<string> wordsadapter = new arrayadapter<string>(c, r.layout.cell_layout, todayspuzzle.searchwords); wordslist.setadapter(wordsadapter); 

here layout gridview (i'm using two, 1 wordsearch , 1 store search words:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/black" tools:context="little.keith.wordsearch.todaysactivity" >  <gridview     android:id="@+id/wordsearchgrid"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentstart="true"     android:layout_alignparenttop="true"     android:layout_margin="4dp"     android:background="@android:color/black"     android:columnwidth="25dp"     android:gravity="top"     android:horizontalspacing="2dp"     android:numcolumns="12"     android:stretchmode="none"     android:verticalspacing="2dp" > </gridview>  <gridview     android:id="@+id/wordslist"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margin="4dp"     android:background="@android:color/black"     android:numcolumns="auto_fit"     android:layout_below="@+id/wordsearchgrid"     android:horizontalspacing="2dp"     android:verticalspacing="2dp"     android:layout_centerhorizontal="true" > </gridview> 

and here cell_layout.xml:

<textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:gravity="center" android:minheight="?android:attr/listpreferreditemheight" android:paddingstart="1dp" android:paddingend="1dp" android:textappearance="?android:attr/textappearancelarge" /> 

managed figure out how myself, sticking answer in case else gets stuck on same problem. fix row heights wrote custom arrayadapter allowed me define cell dimensions setlayoutparams:

public class gridadapter extends arrayadapter {     context context;     object[] items;     int resource;      layoutinflater inflater;      public gridadapter(context context, int resource, object[] items)      {         super(context, resource, items);         this.context = context;         this.resource = resource;         this.items = items;          inflater = (layoutinflater) this.context.getsystemservice(context.layout_inflater_service);     }      @override     public int getcount()      {         return items.length;     }      @override     public object getitem(int position)      {         return items[position];     }      @override     public long getitemid(int position)      {         return position;     }      @override     public view getview(int position, view convertview, viewgroup parent)      {         textview cell;          int cellwidth = 40;         int cellheight = 50;           if (convertview == null)          {             // if convertview null inflate appropriate layout file             convertview = inflater.inflate(resource, null);         }          cell = (textview) convertview.findviewbyid(r.id.gridcell);          cell.settext((charsequence) items[position]);          // set height , width constraints image view         cell.setlayoutparams(new linearlayout.layoutparams(cellwidth, cellheight));          // set padding images         cell.setpadding(1, 1, 1, 1);          return convertview;     } } 

then called in activity:

//fill gridview puzzle input array puzzle class gridadapter gridadapter = new gridadapter(c, r.layout.cell_layout, todayspuzzle.puzzleinputarray); wordsearchgrid.setadapter(gridadapter); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -