Just to answer my own question in case anyone has the same problem.

getCount has to return total number of cells to display in GridView.
So if you want to have 3x3 grid getCount needs to return 9
position in getView is linear e.g. position 7 means row 3 cell 1
convertView is a total mystery as it seems to return random views in
consecutive calls - I ignore it for now and just create new views
every time.

On Dec 16, 10:01 am, loty <lev.pert...@gmail.com> wrote:
> Sorry if I'm asking something trivial but I can't figure it out for
> the life of me. Essentially what I want to have is a simple table like
> GUI and I figured GridView is what I need. I wrote a simple GridView
> test app that sets 3 columns and should have few rows of data. Here is
> my test data
>                 private Row[] mData = {
>                                 new Row("Row1", "Data1", 1999),
>                                 new Row("Row2", "Data2", 2000),
>                                 new Row("Row3", "Data3", 2001),
>                 };
> And this is pretty much how I want this data to be displayed in the
> grid - 3 rows of 3 cells that hold my data. What I can't figure out
> how to do is create views and set values inside individual cells in
> each row.
>
> Here is my code that should populate GridView
> public class GridDataAdapter extends BaseAdapter {
>                 public GridDataAdapter(Context c) {
>                     mContext = c;
>                 }
>
>                 public int getCount() {
>                     return mData.length;
>                 }
>
>                 public View getView(int position, View convertView,
> ViewGroup parent) {
>                     TextView textView;
>                     if (convertView == null) {
>                         textView = new TextView(mContext);
>                         textView.setLayoutParams(new GridView.LayoutParams(45,
> 45));
>                     } else {
>                         textView = (TextView) convertView;
>                     }
>
>                     textView.setText(mData.data1);??? based on
> position??? what is position???
>
>                     return textView;
>                 }
>
> Here is the problem - How do I set values of individual cells in each
> row?
> I know I can create a linear layout with 3 TextViews in my view but
> then I would just be turning gridview into a listview. What should
> getCount return? Number of rows or total number of cells
> (rows*columns)?
> I'm sure I'm missing something obvious here. Please help :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to