Reputation: 153
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
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