我怎样才能循环这个
问题描述:
我怎样才能循环这可以是任何循环?我怎样才能循环这个
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对象,这就是为什么我不能循环它
答
你的意思是这样吗?
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
答
简单:
for(int i=1;i<=3;i++){
ActionBar.Tab tab1 = mActionBar.newTab();
tab1.setText("Tab " + i);
tab1.setTabListener(this);
mActionBar.addTab(tab1);
}
答
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]);
}
答
这里是一个死循环:
boolean i = true;
while(i==true){
//doing
}
我不知道为什么人们downvoting这个问题。显然,OP是编程的新手。 – SMR