user2507301
user2507301

Reputation: 153

Using loops to set a tab title in Android

I have encountered a problem in my Android application where I cannot set tab titles in a loop. Here is my source code:

    for (int i = 0; i < 3; i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText("Converter")
                        .setTabListener(tabListener));
    }

If I try to insert a comma, then put the title of another tab, like this:

                                .setText("Converter", "Currencies", "News")

Eclipse is giving me an error. I have scoured all over the internet to find the answer, but nothing works. Any help would be greatly appreciated.

Upvotes: 0

Views: 202

Answers (1)

user370305
user370305

Reputation: 109237

Using String Array you can do this,

Like,

String[] tabTitle = {"Converter", "Currencies", "News"};

And then,

for (int i = 0; i < 3; i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(tabTitle[i])
                        .setTabListener(tabListener));
    }

Upvotes: 3

Related Questions