zoukankan      html  css  js  c++  java
  • 参数数据自动生成app架构设计【一】

    在写这篇文章之前,xxx已经写过了几篇关于改参数数据主题的文章,想要了解的朋友可以去翻一下之前的文章

         

         

         

        

    1、管理数据对象

         包括获得数据,提交数据

        

    public class WebDateSet{

     

      private HashMap paramList = null; //参数列表

      private String serverUrl = null; //地址

     

      public WebDateSet(String paramString)

      {

        this.serverUrl = paramString;

        this.paramList = new HashMap();

      }

    publicvoid addParam(String param1, String param2)

      {

         this.paramList.put(param1, param2);//添加参数

      }

    //获得数据get

    public List<HashMap> getDateSet(Context paramContext..){

     

    String path = this.serverUrl + "?test=1";

    //for循环下面的paramList{

    path  =path + "&" + str2 + "=" + str3;

    }

    如果没有网络,从安卓数据库里头取

    //表结构:CREATE TABLE datacache (key Text, data Text);

                                if (paramInt == 0) { //无网咯

                                         String xml = new DataCache(paramContext).readCache(path);

    //db.rawQuery("select * from datacache where key=?"

                }else{

    如果有网络,从HttpURLConnection

    dataSet = miijiaoXML.ParserXml(result); //解析获得的

             new DataCache(paramContext).writeCache(path, result);//放到数据库

    }

    }

     

        返回的数据格式为:

        list = new ArrayList<HashMap>();

        if("item".equals(pullParser.getName())){

                 map = new HashMap<String,String>();

        map.put("title", pullParser.nextText()); list.add(map) //1item就是1hashmap

         

        

    2、显示类:

        

    publicclass helloworld extends Activity

    {

      publicvoid onCreate(Bundle paramBundle)

      {

        super.onCreate(paramBundle);

        setContentView(R.layout.show);

     

        HelloContent content = new HelloContent(this, http://baidu.com/, "app_getHellworld.php");

        content.addUrlParam("userid", 1);//get请求的参数,只有这1

    content.addContentItemByImageUrl(R.id.image, "image");

    //要显示的id,及下面值对应的key

        content.addContentItemByText(R.id.title, "title");

        content.addContentItemByHtmlText(R.id.content, "content");

        content.view();

      }

    }

         

         

        

    3、处置类:

        每日一道理
    喜马拉雅直冲霄汉,可下面有攀爬者的旗帜;撒哈拉沙漠一望无垠,可里头有跋涉者的脚印;阿尔卑斯山壁立千仞,可其中有探险者的身影;雅鲁藏布江湍急浩荡,可其中有勇敢者的故事。

        

    publicclass HelloContent

    {

      public ArticleContent(Activity acitvity, String param1, String param2)

      {

        this.activity = acitvity;

        this.webUrl = (param1+ "/" + param2);

        this.wds = new WebDateSet(this.webUrl);

      }

      //添加请求参数

      publicvoid addUrlParam(String paramString1, String paramString2)

      {

        this.wds.addParam(paramString1, paramString2);

      }

     

     //添加显示的控件

      publicvoid addContentItemByText(int paramInt, String paramString)

      {

        HashMap localHashMap = new HashMap();

        localHashMap.put("itemType", "TextView");

        localHashMap.put("dataSetItemName", paramString);

        this.itemList.put(Integer.valueOf(paramInt), localHashMap);

      }

     

      publicvoid addContentItemByImageUrl(int paramInt, String paramString)

      {

        HashMap localHashMap = new HashMap();

        localHashMap.put("itemType", "ImageViewUrl");

        localHashMap.put("dataSetItemName", paramString);

        this.itemList.put(Integer.valueOf(paramInt), localHashMap);

      }

     ……其他的同下面的相似 itemList数据格式为:

    [R.id.text1:[itemType:TextView,dataSetItemName:title]]

     

      publicvoid view()

      {

        List localList = this.wds.getDateSet(this.activity, this.netState);

       

          this.contentData = ((HashMap)localList.get(0));

          showItem();

    }

       }

      privatevoid showItem()

      {

    Iterator item = this.itemList.entrySet().iterator();
        
     for迭代所有的

          String key = item.next().getKey();

        

          HashMap map = (HashMap) item.next().getValue();

          String str1 = (String)map.get("itemType");

          String str2 = (String)map.get("dataSetItemName");

          if ("TextView".equals(str1))

          {

            TextView tt =(TextView)this.activity.findViewById(key);

            tt.setText((String)this.contentData.get(str2));

       }

    }

    }

         

         

    文章结束给大家分享下程序员的一些笑话语录: 问路
    有一个驾驶热气球的人发现他迷路了。他降低了飞行的高度,并认出了地面 上的一个人。他继续下降高度并对着那个人大叫,“打扰一下,你能告诉我我 在哪吗?”
    下面那个人说:“是的。你在热气球里啊,盘旋在 30 英尺的空中”。
    热气球上的人说:“你一定是在 IT 部门做技术工作”。
    “没错”,地面上的人说到,“你是怎么知道的?”
    “呵呵”,热气球上的人说,“你告诉我的每件事在技术上都是对的,但对都没 有用”。
    地面上的人说,“你一定是管理层的人”。
    “没错”,热气球上的人说,“可是你是怎么知道的?”
    “呵呵”,地面上的那人说到,“你不知道你在哪里,你也不知道你要去哪,你 总希望我能帮你。你现在和我们刚见面时还在原来那个地方,但现在却是我 错了”。

  • 相关阅读:
    AtCoder Beginner Contest 167
    AtCoder Beginner Contest 166
    AtCoder Beginner Contest 165
    AtCoder Beginner Contest 164
    AtCoder Beginner Contest 163
    AtCoder Beginner Contest 162
    AtCoder Beginner Contest 161
    AtCoder Beginner Contest 160
    AtCoder Beginner Contest 159
    自定义Mybatis自动生成代码规则
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3076688.html
Copyright © 2011-2022 走看看