使用动态内容生成动态标签

时间:2014-01-13 17:54:20

标签: android json android-tabhost android-tabs android-tabactivity

我有项目,我想在其中创建标签视图,其中所有标签都是从json生成的 依赖于json。 选项卡视图的内容是列表视图,listview数据再来自json。

这里我提供了我的json文件

“checks”{“check”:{
                  “ref”:”1”,
                  “area”:”In Cab”,
                  “title”:”Condition of windscreen”,
                   “description”:”Check there are no cracks, that the windscreen is                          clean and not greasy.”,
                  “controlType”:”Check”,
                  “checkResult”:””,
                  “checkValue”:””
                },
        “check”:{
                 “ref”:”2”,
                 “area”:”External”,
                 “title”:”Windscreen wipers”,
                 “description”:”Check the wiper surface is smooth and not cut and the   wiper touches the screen on its full length.”,
                 “controlType”:”Check”,
                 “checkResult”:””,
                 “checkValue”:”” 
                },
        “check”:{
                 “ref”:”3”,
                 “area”:”Input”,
                 “title”:”Registration”,
                 “description”:”Enter the registration number for the vehicle.”,
                 “controlType”:”TEXT”,
                 “checkResult”:””,
                 “checkValue”:””
                },
       “check”:{
                “ref”:”4”,
                “area”:”Input”,
                “title”:”Mileage”,
                “description”:”Enter the mileage for the vehicle.”,
                “controlType”:”NUMBER”,
                “checkResult”:””,
                “checkValue”:””
               },
      “check”:{
               “ref”:”5”,
               “area”:”Input”,
               “title”:”Tacho Expiry Date”,
               “description”:”enter the tacho expiry date.”,
               “controlType”:”DATE”,
               “checkResult”:””,
               “checkValue”:””
              },
      “check”:{
               “ref”:”6”,
               “area”:”Input”,
               “title”:”Warning light colour”,
               “description”:”Enter the warning light colour.”,
               “controlType”:”SELECT”,
               “selectValues”:”’Red, ‘Amber’,’’Green”,
               “checkResult”:””,
                “checkValue”:””
               }
}

此处标签是基于json

中的区域标签创建的

并且标签的内容基于标题,描述的区域 所以我很困惑如何创建标签以及如何在不同的标签中添加内容

提前感谢

1 个答案:

答案 0 :(得分:1)

试试这个:

btnAddTab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            TabHost.TabSpec spec = tabHost.newTabSpec("Tab"+i);
            spec.setContent(new TabHost.TabContentFactory() {
                @Override
                public View createTabContent(String tag) {
                    return new AnalogClock(MainActivity.this);
                }
            });
            spec.setIndicator("Clock");
            tabHost.addTab(spec);
        }
    });