【发布时间】:2014-03-09 08:13:37
【问题描述】:
我正在开发一个使用标签栏的应用程序。我关注This Link. 我根据应用程序做了一些更改:我的标签文本意味着标题来自 SQLite 数据库,我存储在一个数组中并在循环中传递给 TabSpec。
代码如下:
DataBaseHelper dataBaseHelper = new DataBaseHelper(this);
try {
dataBaseHelper.createDataBase();
} catch (IOException e) {
e.printStackTrace();
}
dataBaseHelper.openDataBase();
Cursor c = dataBaseHelper.getDataFromDataBase();
String[] name = new String[c.getCount()];
int i=0;
if(c.getCount() > 0){
if(c.moveToFirst()){
do{
name[i] = c.getString(0);
i++;
} while(c.moveToNext());
}
}
TabHost tabHost = getTabHost();
for(int j = 0; j < name.length; j++){
String tabTitle = name[j];
TabSpec photospec = tabHost.newTabSpec(tabTitle);
photospec.setIndicator(tabTitle, null);
Intent photosIntent = new Intent (this, PhotosActivity. class). addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
photosIntent.putExtra("name", tabTitle);
photospec.setContent(photosIntent);
tabHost.addTab(photospec);
}
这段代码运行良好。但现在想将背景设置为我的标签。因此,为此我放了一些 inmages n 可绘制文件夹并制作了一个数组:
Integer[] imageIDsTemp= new Integer[]{
R.drawable.tb01,
R.drawable.tb02,
R.drawable.tb03,
R.drawable.tb04,
R.drawable.tb05,
R.drawable.tb06,
R.drawable.tb07,
R.drawable.tb08,
R.drawable.tb09,
R.drawable.tb10,
R.drawable.tb11,
R.drawable.tb12,
};
但是如何将这个数组传递给
TabSpec photospec = tabHost.newTabSpec(tabTitle);
执行此操作时出现错误。我尝试的是:
TabSpec photospec = tabHost.newTabSpec(tabTitle);
photospec.setIndicator(tabTitle, imageIDsTemp[j]);
请指导我如何为标签分配图像和颜色。
【问题讨论】:
-
你能把你得到的错误贴出来吗?
标签: android android-layout tabs android-tabhost android-tabs