手记

Andrioid天气

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

 

[代码]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>


0人推荐
随时随地看视频
慕课网APP