hsiao 7 yıl önce
ebeveyn
işleme
f977f9685b

+ 1
- 0
lesson01/src/main/java/io/hsiao/lesson01/MainActivity.java Dosyayı Görüntüle

@@ -78,6 +78,7 @@ public class MainActivity extends AppCompatActivity {
78 78
     }
79 79
 
80 80
     private void notifyToast(String msg) {
81
+
81 82
         Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
82 83
     }
83 84
 

+ 3
- 1
lesson02/src/main/AndroidManifest.xml Dosyayı Görüntüle

@@ -12,7 +12,6 @@
12 12
         <activity android:name=".MainActivity">
13 13
             <intent-filter>
14 14
                 <action android:name="android.intent.action.MAIN" />
15
-
16 15
                 <category android:name="android.intent.category.LAUNCHER" />
17 16
             </intent-filter>
18 17
         </activity>
@@ -30,5 +29,8 @@
30 29
             </intent-filter>
31 30
         </activity>
32 31
     </application>
32
+    <uses-permission android:name="android.permission.INTERNET" />
33
+    <uses-permission android:name="android.permission.CALL_PHONE"/>
34
+    <uses-permission android:name="android.permission.CAMERA" />
33 35
 
34 36
 </manifest>

+ 67
- 2
lesson02/src/main/java/io/hsiao/lesson02/MainActivity.java Dosyayı Görüntüle

@@ -7,9 +7,12 @@ import android.support.v7.widget.Toolbar;
7 7
 import android.util.Log;
8 8
 import android.view.Menu;
9 9
 import android.view.MenuItem;
10
+import android.view.View;
11
+import android.widget.AdapterView;
10 12
 import android.widget.ArrayAdapter;
11 13
 import android.widget.ListView;
12 14
 import android.widget.SimpleAdapter;
15
+import android.widget.TextView;
13 16
 import android.widget.Toast;
14 17
 
15 18
 import java.text.SimpleDateFormat;
@@ -30,7 +33,9 @@ public class MainActivity extends AppCompatActivity {
30 33
     protected void onCreate(Bundle savedInstanceState) {
31 34
         super.onCreate(savedInstanceState);
32 35
         setContentView(R.layout.activity_main);
36
+        //获取应用栏
33 37
         Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
38
+        //设置应用栏
34 39
         setSupportActionBar(toolBar);
35 40
         Log.i("youmap", "MainActivity创建完成");
36 41
 
@@ -38,8 +43,68 @@ public class MainActivity extends AppCompatActivity {
38 43
     }
39 44
 
40 45
     private void createListView() {
46
+        //获取ListView
41 47
         this.listView = (ListView) findViewById(R.id.main_listview);
42
-        this.listView.setAdapter(new SimpleAdapter(this, getData(), R.layout.home_list, new String[]{"title", "thumbnail", "date"}, new int[]{R.id.home_list_title, R.id.home_list_date, R.id.home_list_desc}));
48
+
49
+        /**
50
+         * <pre>
51
+         *   新建数据适配器。传入:
52
+         *   1: Activity实例,即this对象。
53
+         *   2: 数据内容
54
+         *   3:Item的布局
55
+         *   4:数据里对应布局的Key值
56
+         *   5:布局与数据对应的组件Id
57
+         * </pre>
58
+         *
59
+         */
60
+        SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.home_list, new String[]{"title", "thumbnail", "date"}, new int[]{R.id.home_list_title, R.id.home_list_date, R.id.home_list_desc});
61
+
62
+        /**
63
+         * 通过setAdapter方法,绑定数据和布局。
64
+         */
65
+        this.listView.setAdapter(adapter);
66
+
67
+        /**
68
+         * 绑定Item的click方法。
69
+         */
70
+        this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
71
+            /**
72
+             *
73
+             * @param parent
74
+             * @param view item控件,即整个Item的布局。
75
+             * @param position
76
+             * @param id
77
+             */
78
+            @Override
79
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
80
+                //在传入的Item布局里获取到需要的控件。
81
+                TextView txt = (TextView) view.findViewById(R.id.home_list_title);
82
+                Toast.makeText(MainActivity.this, txt.getText(), Toast.LENGTH_SHORT).show();
83
+
84
+                Intent intent = new Intent(MainActivity.this, MessageActivity.class);
85
+
86
+                startActivity(intent);
87
+            }
88
+        });
89
+
90
+        /**
91
+         * 绑定Item的长按方法。
92
+         */
93
+        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
94
+            @Override
95
+            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
96
+                Intent intent = new Intent();
97
+                intent.setAction(Intent.ACTION_SEND);
98
+                intent.putExtra(Intent.EXTRA_TEXT, "110");
99
+                intent.setType("text/plain");
100
+
101
+                if (intent.resolveActivity(getPackageManager()) != null) {
102
+                    startActivity(intent);
103
+                }
104
+
105
+                return true;
106
+            }
107
+        });
43 108
     }
44 109
 
45 110
     private List<HashMap<String, Object>> getData() {
@@ -48,7 +113,7 @@ public class MainActivity extends AppCompatActivity {
48 113
             HashMap<String, String> map = new HashMap<>();
49 114
             map.put("title", "标题 " + i);
50 115
             map.put("thumbnail", "图片 " + i);
51
-            map.put("date", sdf.format(new Date()));
116
+            //map.put("date", sdf.format(new Date()));
52 117
 
53 118
             list.add(map);
54 119
         }

+ 1
- 0
lesson02/src/main/java/io/hsiao/lesson02/UserCenterActivity.java Dosyayı Görüntüle

@@ -21,6 +21,7 @@ public class UserCenterActivity extends Activity {
21 21
             public void onClick(View v) {
22 22
                 Intent intent = new Intent();
23 23
                 intent.setAction(Intent.ACTION_SEND);
24
+                //intent.putExtra(Intent.EXTRA_TEXT,"13888888888");
24 25
                 intent.putExtra(Intent.EXTRA_TEXT,"Hi, 我是John,炒鸡帅男。我的Email是 John@gmail.com。");
25 26
                 intent.setType("text/plain");
26 27
 

+ 9
- 0
lesson02/src/main/res/drawable/ic_apps_black_24dp.xml Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"/>
9
+</vector>

+ 9
- 0
lesson02/src/main/res/drawable/ic_message_black_24dp.xml Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
9
+</vector>

+ 9
- 0
lesson02/src/main/res/drawable/ic_search_black_24dp.xml Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+        android:width="24dp"
3
+        android:height="24dp"
4
+        android:viewportWidth="24.0"
5
+        android:viewportHeight="24.0">
6
+    <path
7
+        android:fillColor="#FF000000"
8
+        android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
9
+</vector>

+ 7
- 0
lesson02/src/main/res/layout/activity_user_center.xml Dosyayı Görüntüle

@@ -24,4 +24,11 @@
24 24
         android:layout_width="match_parent"
25 25
         android:layout_height="wrap_content"
26 26
         android:text="分享我的名片" />
27
+
28
+    <TextView
29
+        android:id="@+id/usercenter_weblink"
30
+        android:layout_width="match_parent"
31
+        android:layout_height="wrap_content"
32
+        android:autoLink="web"
33
+        android:text="http://www.baidu.com" />
27 34
 </LinearLayout>

+ 3
- 1
lesson02/src/main/res/menu/menu.xml Dosyayı Görüntüle

@@ -3,10 +3,11 @@
3 3
 
4 4
     <item
5 5
         android:id="@+id/menu_item_message"
6
-        android:title="消息"
6
+        android:icon="@drawable/ic_message_black_24dp"
7 7
         app:showAsAction="always" />
8 8
     <item
9 9
         android:id="@+id/menu_item_mapps"
10
+        android:icon="@drawable/ic_apps_black_24dp"
10 11
         android:title="微应用"
11 12
         app:showAsAction="always" />
12 13
     <item
@@ -20,6 +21,7 @@
20 21
         android:title="通讯录" />
21 22
     <item
22 23
         android:id="@+id/menu_item_search"
24
+        android:icon="@drawable/ic_search_black_24dp"
23 25
         android:title="搜索"
24 26
         app:showAsAction="always" />
25 27
 </menu>

+ 1
- 1
lesson02/src/main/res/values/colors.xml Dosyayı Görüntüle

@@ -1,4 +1,4 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <resources>
3
-    <color name="colorPrimary">#1f9cd6</color>
3
+    <color name="colorPrimary">#ff5722</color>
4 4
 </resources>

Loading…
İptal
Kaydet