• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            life02

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              197 隨筆 :: 3 文章 :: 37 評論 :: 0 Trackbacks
            android 中通過 aidl 傳遞map對象
            http://blog.sina.com.cn/s/blog_7a4b93580100um3s.html
                分類: android
            思路: aidl傳遞
            -------intent(包含一個bundle對象而bundle中放的是Bundle.putSerializable(String key, Serializable value))--------Serializable value(這里我想放的是一個map對象)-----HashMap(Map<String, ArrayList<Entity>>  String為這個數(shù)據(jù)集合的一個標記可以通過這個標記獲取這個數(shù)據(jù)集合)---- ArrayList<Entity> (實體的數(shù)據(jù)集合類)。

            雜癥:Serializable value
            實體Entity實現(xiàn)了序列化接口,依然不可傳遞。解決辦法是將map封裝了一下,實現(xiàn)了序列化接口就OK了。

            實例:某哥們的demo(用了兩個Activity,一個傳遞數(shù)據(jù),另一個接受數(shù)據(jù)):

            封裝的map:

            public class MyMap implements Serializable{



                
            private Map<String, ArrayList<Entity>> map;



                
            public Map<String, ArrayList<Entity>> getMap() {

                    
            return map;

                }



                
            public void setMap(Map<String, ArrayList<Entity>> map) {

                    
            this.map = map;

                }

                

            }

            實體Entity:

              

            public class Entity implements Serializable{

              String id;

              String name;

              String age;

                
            public String getId() {

                    
            return id;

                }

                
            public void setId(String id) {

                    
            this.id = id;

                }

                
            public String getName() {

                    
            return name;

                }

                
            public void setName(String name) {

                    
            this.name = name;

                }

                
            public String getAge() {

                    
            return age;

                }

                
            public void setAge(String age) {

                    
            this.age = age;

                }

                  

            }

             用于傳遞數(shù)據(jù)的Activity:

            public class MapDemoActivity extends Activity {

                Button button;

                

                @Override

                
            public void onCreate(Bundle savedInstanceState) {

                    
            super.onCreate(savedInstanceState);

                    setContentView(R.layout.main);

                    

                    Map
            <String, ArrayList<Entity>> map=initData();

                    
            final MyMap myMap=new MyMap();

                    
            //將map數(shù)據(jù)添加到封裝的map中
                    myMap.setMap(map);

                    

                    button
            =(Button) findViewById(R.id.btn);

                    button.setOnClickListener(
            new OnClickListener() {

                        

                        
            public void onClick(View v) {

                            
            // TODO Auto-generated method stub
                            Intent intent=new Intent(MapDemoActivity.this,ReceiveMap.class);

                            Bundle bundle
            =new Bundle();

                            bundle.putSerializable(
            "map", myMap);

                            intent.putExtras(bundle);

                            startActivity(intent);

                        }

                    });

                }

                

                
            private Map<String, ArrayList<Entity>> initData() {

                    
            // TODO Auto-generated method stub
                    Map<String, ArrayList<Entity>> map=new HashMap<String, ArrayList<Entity>>();

                      
            for(int i=0;i<10;i++){

                        ArrayList
            <Entity> list=new ArrayList<Entity>();

                          
            for(int j=0;j<10;j++){

                              Entity entity
            =new Entity();

                              entity.setId(
            ""+j);

                              entity.setName(
            "name"+j);

                              entity.setAge(
            "age"+j);

                              list.add(entity);

                          }

                          map.put(
            "path"+i, list);

                      }

                    
            return map;

                }

                

                

            }

              

            用來接受數(shù)據(jù)的Activity:

            public class ReceiveMap extends Activity {

                TextView textView;

                Button  button;

                MyMap myMap;

                
            protected void onCreate(Bundle savedInstanceState) {

                    
            // TODO Auto-generated method stub
                    super.onCreate(savedInstanceState);

                    setContentView(R.layout.receive_data);

                    

                    Bundle bundle
            =getIntent().getExtras();

                    myMap
            =(MyMap) bundle.get("map");

                    

                    textView
            =(TextView) findViewById(R.id.tv);

                    button
            =(Button) findViewById(R.id.receive_btn);

                    button.setOnClickListener(
            new OnClickListener() {

                        

                        
            public void onClick(View v) {

                            
            // TODO Auto-generated method stub
                            Map<String, ArrayList<Entity>> map=myMap.getMap();

                            
            if(map==null)

                                
            return ;

                            
            for(int i=0;i<10;i++){

                                ArrayList
            <Entity> list=map.get("path"+i);

                                
            if(list==null||list.size()==0)

                                    
            continue;

                                    textView.append(
            "map key--"+"path"+i+"---list size is---"+list.size()+"\n");

                            }

                        }

                    });

                }

               

            }

            posted on 2012-04-06 14:08 life02 閱讀(4168) 評論(0)  編輯 收藏 引用 所屬分類: Android開發(fā)
            久久精品黄AA片一区二区三区| 99久久免费只有精品国产| 久久人搡人人玩人妻精品首页| 久久人人爽人人爽人人AV东京热| 美女写真久久影院| 亚洲国产成人久久综合野外| 伊色综合久久之综合久久| 久久久久高潮毛片免费全部播放 | 久久激情五月丁香伊人| 欧美午夜A∨大片久久| 国产精品久久久亚洲| 国产精品久久久久久久app| 久久国产精品77777| 久久久久国产亚洲AV麻豆| 麻豆亚洲AV永久无码精品久久| 人妻无码久久精品| 丁香五月网久久综合| 久久亚洲精品国产亚洲老地址| 久久高清一级毛片| 国产精品久久久久影视不卡| 亚洲Av无码国产情品久久| 国产国产成人久久精品| 久久天天躁狠狠躁夜夜96流白浆| 很黄很污的网站久久mimi色| 久久精品人妻中文系列| 久久亚洲中文字幕精品一区四| 51久久夜色精品国产| 99久久久国产精品免费无卡顿| 久久无码AV一区二区三区| 久久国产乱子伦精品免费强| 亚洲AV无一区二区三区久久| 久久国产劲爆AV内射—百度| 四虎国产精品成人免费久久| 国产精品永久久久久久久久久 | 国产美女久久久| 久久午夜无码鲁丝片秋霞| 亚洲精品美女久久久久99小说 | 狠狠色丁香婷综合久久| 久久狠狠高潮亚洲精品| 99久久免费国产特黄| 久久人爽人人爽人人片AV|