2017-03-06 162 views
-5

我怎样才能循环这可以是任何循环?我怎样才能循环这个

ActionBar.Tab tab1 = mActionBar.newTab(); 
tab1.setText("Tab 1"); 
tab1.setTabListener(this); 

ActionBar.Tab tab2 = mActionBar.newTab(); 
tab2.setText("Tab 2"); 
tab2.setTabListener(this); 

//so that i cannot repeat the code again and again 
//enhance for loop/ while /for 

ActionBar.Tab tab3 = mActionBar.newTab(); 
tab3.setText("Tab 3"); 
tab3.setTabListener(this); 

//i have declare three taps for swipe app 

mActionBar.addTab(tab1); 
mActionBar.addTab(tab2); 
mActionBar.addTab(tab3); 

我在Java初学者和Android工作室他们是Java对象,这就是为什么我不能循环它

+0

我不知道为什么人们downvoting这个问题。显然,OP是编程的新手。 – SMR

回答

0

你的意思是这样吗?

for(int i = 0; i<numberOfRepeat; i++){ 
     ActionBar.Tab tab1 = mActionBar.newTab(); 
     tab1.setText("Tab " + String.valueOf(i)); 
     tab1.setTabListener(this); 
     mActionBar.addTab(tab1); 
    } 
+0

tab1.setText(“Tab”+ String.valueOf(i + 1)); – Aryan

1

简单:

for(int i=1;i<=3;i++){ 
    ActionBar.Tab tab1 = mActionBar.newTab(); 
    tab1.setText("Tab " + i); 
    tab1.setTabListener(this); 
    mActionBar.addTab(tab1); 
} 
0
int total=3; 
ActionBar.Tab tab[]=new ActionBar.Tab[total]; 

for(int i=0;i<tab.length;i++){ 
    tab[i]=mActionBar.newTab(); 
    tab[i].setText("Tab " + String.valueOf(i+1)); 
    tab[i].setTabListener(this); 
    mActionBar.addTab(tab[i]); 
} 
+1

只有代码答案是不鼓励的。为了帮助他人,请包括上述如何/为什么有助于解决问题的简要说明。 [来自评论](http://stackoverflow.com/review/low-quality-posts/15433211)。 – Leigh

+0

@Leigh代码非常简单,所以我不这么认为需要任何解释。 – Aryan

+0

我听到你在说什么,但请记住,不是每个人都阅读这篇文章的技能水平与你的相同。从长远来看,添加一个简短的解释使得答案对更广泛的用户更有用。 – Leigh

0

这里是一个死循环:

boolean i = true; 
while(i==true){ 
//doing 
    } 
相关问题