继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Andrioid天气

弑天下
关注TA
已关注
手记 141
粉丝 12
获赞 51

原文链接:http://www.apkbus.com/blog-725801-62074.html

 5bada936000132d603930578.jpg

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

public ArrayList<string> getCityList(){ 

        ArrayList<string>   cityList1=new ArrayList<string>(); 

        Map<string,string>   map=(Map<string, string="">)   sharedPreferences.getAll(); 

        Collection<string>   collection=map.values(); 

        Iterator<string>   iterator=collection.iterator(); 

           

        while(iterator.hasNext()){   

            String   city=iterator.next(); 

            System.out.println("城市----"+city);   

            if(!(city.equals("0")||city.equals("1"))){   

                cityList1.add(city);   

            }              

        }   

        //用一个HashSet来将cityList1里面的重复元素去除 

        HashSet<string>   h=new HashSet<string>(cityList1); 

        cityList1.clear();         

        cityList1.addAll(h);   

        return cityList1;      

    } 

       

    /*

     * 增加城市

     */ 

    public boolean   setCityList(String key,String value){ 

        SharedPreferences.Editor   editor=sharedPreferences.edit(); 

        editor.putString(key,   value); 

        boolean   isSet=editor.commit(); 

        return   isSet; 

    } 

    /*

     * 删除城市

     */ 

    public boolean   deleteCity(String key){ 

        SharedPreferences.Editor   editor=sharedPreferences.edit(); 

        editor.remove(key);   

        boolean   isDelete=editor.commit(); 

        return   isDelete; 

    } 

       

    /*

     * 双击退出

     * @see   android.app.Activity#onKeyDown(int, android.view.KeyEvent)

     */ 

    @Override 

    public boolean onKeyDown(int keyCode,   KeyEvent event) { 

        switch (keyCode)   { 

        case KeyEvent.KEYCODE_BACK:   

            if(System.currentTimeMillis()-time>2000){   

                Toast.makeText(this,   "退出?", 1000).show(); 

                time=System.currentTimeMillis();   

            }else{   

                finish();   

            }   

               

            return   false; 

   

        default:   

            break;   

        }   

        return super.onKeyDown(keyCode,   event); 

    } 

}    \</string></string></string></string></string,></string,string></string></string></string>

?

1

<br>


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP