omi
omi

Reputation: 145

dynamicly adding textView's to gridView in android

I'm trying to create a gridView based on a length of a string.

Every textView should show a single char - an underline - and assuming that there are no space in the string...

I've Previously did something similar in c#- I craeted a tableview which containes 15 lables, and based on the number of letters, moved each of them the the right. it looks more or less like this:

public void setLetters(String str)
        {
            tableLayoutPanel1.Visible = false;
            int x = revah(str); //revah returns the number of letters in the string
            int yy = x / 2;
            int count = 0;
            if (count <= x)
            {
                tableLayoutPanel1.SetColumn(lbl0, yy);
                count++;
            }
            if (count <= x)
            {
                tableLayoutPanel1.SetColumn(lbl1, yy);
                count++;
            }
            if (count <= x)
            {
                tableLayoutPanel1.SetColumn(lbl2, yy);
                count++;
            }
            if (count <= x)
            {
                tableLayoutPanel1.SetColumn(lbl3, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl4, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl5, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl6, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl7, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl8, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl9, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl10, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl11, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl12, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl13, yy);
            count++;
        }
        if (count <= x)
        {
            tableLayoutPanel1.SetColumn(lbl14, yy);
            count++;
        }

        tableLayoutPanel1.Visible = true;

    } 

I wish to do something similar in android, using gridView, but have no idea how to even start... help...

Upvotes: 2

Views: 3028

Answers (2)

Zohaib
Zohaib

Reputation: 2865

Follow this link this will show how to make grid view , what u want now. u have to make an method that will read you textview value and then make a logic to split those word in single character and than add those character in string[] . Hope this will help

Upvotes: 1

mari
mari

Reputation: 874

You could create a layout with a GridView (inflated by an Activity - http://developer.android.com/reference/android/app/Activity.html) and other layout with your textview's. After that, you have to implement an Adapter to populate the GridView (an ArrayAdapter) with the strings (in the method getView). The method getCount() will determine the number of items. This methods are in ArrayAdapter class, you have to override them. Check here: http://developer.android.com/reference/android/widget/ArrayAdapter.html

Upvotes: 1

Related Questions