【问题标题】:Multiple Hash table objects into single Object or Array?将多个哈希表对象转换为单个对象或数组?
【发布时间】:2012-01-04 09:14:45
【问题描述】:

我有 10 个哈希表,我需要将所有这 10 个哈希表存储到单个实例中,例如数组。我想将选定的哈希表传递给另一个类/活动。 我怎样才能做到这一点?谢谢。

【问题讨论】:

    标签: android arrays hashtable


    【解决方案1】:

    创建你的类:

    public class Maps implements Parcelable {
        Map[] mapArray = new Map[10];
    
        public Map[] getMapArray() {
            return mapArray;
        }
    
        public void setMapArray(Map[] mapArray) {
            this.mapArray = mapArray;
        }
    
        @Override
        public int describeContents() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            // TODO Auto-generated method stub
    
        }
    
    }
    

    然后在活动中做接下来的事情:

     Intent intent = new Intent(); // create intent that call your another activity
     Maps maps = new Maps(); // create maps object.
     maps.getMapArray();        // mark your selected maps
     intent.putExtra("Maps", maps); // put key for your object
     startActivity(intent);// start your another activity.
    

    在另一个活动中,通过“地图”键获取此对象并使用它。

    【讨论】:

    • 10 个哈希表没问题,但是我们怎样才能使用更多的哈希表呢?​​
    • 创建增加数组并将更多哈希表放入其中的方法。
    • 如何在其他类/意图中获取该数据?
    • 捆绑附加服务 = getIntent().getExtras(); extras.getParcelable("地图");
    【解决方案2】:

    我解决了我的问题如下

     List<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>();
    

    循环中

        Hashtable<String, String> hm = new Hashtable<String, String>();
    // Put elements to the map
    
    hm.put("Read_Flag", s1);
    hm.put("sms_received_id", s2);
    hm.put("Sender_Id", s3);
    hm.put("Sender_Name", s4);
    hm.put("Patient_Name", s5);
    hm.put("Received_Date", s6);
    hm.put("Received_Text", s7);
    hm.put("Received_Text_Full", s8);
    hm.put("AttachmentFlag", s9);
    
    // Get a set of the entries
    Set<?> set = hm.entrySet();
    // Get an iterator
    Iterator<?> it = set.iterator();
    // Display elements
    while(it.hasNext()) {
    Map.Entry me = (Map.Entry)it.next();
    
    }
    //System.out.println(hm);
    
    info.add(hm);
    

    //循环结束

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 2020-06-17
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 2021-11-07
      • 1970-01-01
      相关资源
      最近更新 更多