Android九宮格界面實現點擊每一個格點擊跳轉界面

剛開始有個任務就是作一個九宮格界面,後來有個任務就是實現點擊每一個格並跳轉界面實現每一個格的功能。下面我就介紹一下我是如何實現該功能的java

首先寫一下個人想法是:android

登陸成功後顯示一個九宮格界面,每一個九宮格的每個都是一個功能模塊,當點擊每一個模塊時,就會跳轉到相應的界面並實現該模塊所具有的功能。app

下面是以"綜合實踐管理系統"這個格來實現的,當咱們點擊該按鈕時,他就會跳轉到"學生綜合實踐模塊積分申請表"這個界面而後咱們經過下拉菜單選擇本身想要申請的項目。而後點擊"下一步"咱們就跳轉到補充信息這個界面了,實現上傳照片還有補充信息這個功能界面。ide

第二步:跳轉到下面這個界面ui

第三步點擊下一步跳轉到完善信息這個界面this

點擊加號上傳你要加分的證實圖片,這個照片能夠調用相機照也能夠是從相冊中獲取spa

點擊從相冊中獲取會設計

 

下面就是我用到的控件及控件的用法。3d

  1 package com.itcast.test03;

3 import java.util.ArrayList; 4 import java.util.HashMap; 6 import android.os.Bundle; 7 import android.app.Activity; 8 import android.content.Intent; 9 import android.view.Menu; 10 import android.view.View; 11 import android.view.ViewGroup; 12 import android.widget.AdapterView; 13 import android.widget.AdapterView.OnItemClickListener; 14 import android.widget.BaseAdapter; 15 import android.widget.GridView; 16 import android.widget.ImageView; 17 import android.widget.SimpleAdapter; 18 import android.widget.TextView; 19 import android.widget.Toast; 20 21 public class StudentMainActivity extends Activity { 22 private GridView gridview; 23 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 super.onCreate(savedInstanceState); 27 setContentView(R.layout.activity_student_main); 28 gridview = (GridView)findViewById(R.id.gridView1); 29 ArrayList<HashMap<String,Object>> lstImageItem = new ArrayList<HashMap<String,Object>>(); 30 for(int i = 1;i<20;i++){ 31 HashMap<String,Object> map = new HashMap<String, Object>(); 32 if(i==1){ 33 map.put("ItemImage", R.drawable.ic_launcher02); 34 map.put("ItemText", "實踐教學管理系統"); 35 36 }else if(i==2){ 37 map.put("ItemImage", R.drawable.ic_launcher06); 38 map.put("ItemText", "畢業設計管理系統"); 39 40 }else if(i==3){ 41 map.put("ItemImage", R.drawable.ic_launcher02); 42 map.put("ItemText", "開放實驗管理系統"); 43 44 }else if(i==4){ 45 map.put("ItemImage", R.drawable.ic_launcher03); 46 map.put("ItemText", "實習實訓管理系統"); 47 48 }else if(i==5){ 49 map.put("ItemImage", R.drawable.ic_launcher05); 50 map.put("ItemText", "班級事務管理系統"); 51 52 }else if(i==6){ 53 map.put("ItemImage", R.drawable.ic_launcher06); 54 map.put("ItemText", "綜合實踐管理系統"); 55 56 }else if(i==7){ 57 map.put("ItemImage", R.drawable.ic_launcher04); 58 map.put("ItemText", "其餘事物2管理系統"); 59 60 }else if(i==8){ 61 map.put("ItemImage", R.drawable.ic_launcher08); 62 map.put("ItemText", "其餘事物3管理系統"); 63 64 }else if(i==9){ 65 map.put("ItemImage", R.drawable.ic_launcher01); 66 map.put("ItemText", "其餘事物4管理系統"); 67 68 }else if(i==10){ 69 map.put("ItemImage", R.drawable.ic_launcher02); 70 map.put("ItemText", "開放實驗管理系統"); 71 72 }else if(i==11){ 73 map.put("ItemImage", R.drawable.ic_launcher03); 74 map.put("ItemText", "實習實訓管理系統"); 75 76 }else if(i==12){ 77 map.put("ItemImage", R.drawable.ic_launcher05); 78 map.put("ItemText", "班級事務管理系統"); 79 80 }else if(i==13){ 81 map.put("ItemImage", R.drawable.ic_launcher06); 82 map.put("ItemText", "綜合實踐管理系統"); 83 84 }else if(i==14){ 85 map.put("ItemImage", R.drawable.ic_launcher04); 86 map.put("ItemText", "其餘事物2管理系統"); 87 88 }else if(i==15){ 89 map.put("ItemImage", R.drawable.ic_launcher08); 90 map.put("ItemText", "其餘事物3管理系統"); 91 92 }else if(i==16){ 93 map.put("ItemImage", R.drawable.ic_launcher01); 94 map.put("ItemText", "其餘事物4管理系統"); 95 96 } 97 lstImageItem.add(map); 98 } 99 SimpleAdapter saImageItems = new SimpleAdapter(this, 100 lstImageItem,R.layout.next_activity_student_main, 101 new String[]{"ItemImage","ItemText"}, 102 new int[] {R.id.ItemImage,R.id.ItemText}); 103 gridview.setAdapter(saImageItems); 104 gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 105 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 106 long arg3) { 107 int index = arg2 + 1;// id是從0開始的,因此須要+1 108 if (index == 1) { 109 110 Intent intent = new Intent(); 111 intent.setClass(StudentMainActivity.this, 112 StudentNextMainActivity.class); 113 startActivity(intent); 114 } 115 if (index == 2) { 116 Intent intent = new Intent(); 117 intent.setClass(StudentMainActivity.this, 118 StudentNextMainActivity.class); 119 startActivity(intent); 120 121 } 122 123 } 124 }); 125 126 127 128 129 130 } 131 }

 

 

 

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2          android:layout_width="match_parent"
 3          android:layout_height="wrap_content"              
 4          android:orientation="vertical" >
 5 
 6      <RelativeLayout 
 7              android:id="@+id/rl_username"
 8              android:layout_width="match_parent"
 9              android:layout_height="wrap_content"            
10              android:background="#000000">
11              <TextView 
12                  android:id="@+id/tv_name"
13                  android:layout_width="match_parent"
14                  android:layout_height="wrap_content"
15                  android:layout_centerVertical="true"
16                  android:layout_margin="35dp"
17                  android:textSize="20sp"
18                  android:textColor="#FFFFFF"
19                  android:text="歡迎登陸軟件學院管理系統"/>     
20          </RelativeLayout>
21 
22     <LinearLayout
23         android:layout_width="match_parent"
24         android:layout_height="wrap_content"        
25         android:orientation="vertical" >                 
26     <GridView
27         android:id="@+id/gridView1"
28         android:layout_width="match_parent"
29         android:layout_height="wrap_content"
30         android:numColumns="3" >
31     </GridView>
32 </LinearLayout>
33 </LinearLayout>
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="fill_parent"
 3     android:layout_height="wrap_content" >
 4 
 5     <ImageView
 6         android:id="@+id/ItemImage"
 7         android:layout_width="50dp"
 8         android:layout_height="50dp"
 9        android:layout_centerHorizontal="true"/>
10 
11     <TextView
12         android:id="@+id/ItemText"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15           android:layout_centerHorizontal="true"
16         android:layout_below="@+id/ItemImage"
17         android:layout_marginTop="24dp"
18         android:textColor="#000000"
19         android:textSize="12sp"  />
20    
21 </RelativeLayout>

 以上是實現這個界面的代碼code

  1 package com.itcast.test03;
  2 
  3 import android.os.Bundle;
  4 import android.app.Activity;
  5 import android.view.Menu;
  6 import java.io.File;
  7 import java.io.FileOutputStream;
  8 import android.os.Environment;
  9 import android.content.Intent;
 10 import android.graphics.Bitmap;
 11 import android.view.View;
 12 import android.widget.AdapterView;
 13 import android.widget.ArrayAdapter;
 14 import android.widget.Spinner;
 15 public class StudentNextMainActivity extends Activity
 16 {
 17     private Spinner projectsSpinner = null;  
 18     private Spinner kindsSpinner = null;    
 19     private Spinner examinesSpinner = null;   
 20     ArrayAdapter<String>  projectsAdapter = null;  
 21     ArrayAdapter<String> kindsAdapter = null;    
 22     ArrayAdapter<String> examinesAdapter = null;    
 23     static int provincePosition = 3;   
 24     private String[] projects = new String[] {"科研訓練","素質拓展","社會實踐"};
 25     private String[][] kinds = new String[][] 
 26             {
 27                     { "項目類", "成果類", "學術活動"},
 28                     { "專業素質", "綜合素質"},
 29                     { "無"}
 30             };
 31 
 32 
 33     private String[][][] examines = new String[][][] 
 34             {
 35                     { //科研訓練
 36                         {"主持或參加科研項目","校大學生創新基金重點項目","校大學生創新基金通常項目"},
 37                         {"獲獎","著做","專利","論文"},
 38                         {"學術交流","學術講座","課外讀書"}
 39                     },
 40                     {    //素質拓展
 41                         {"學科競賽(含挑戰杯)","證書"},
 42                         {"開放實驗","參加文體活動","組織活動"}
 43                     },
 44                     {    //社會實踐
 45                         {"社會實踐活動","社團活動","公益勞動","自主創業"}
 46                     }
 47             };
 48 
 49     
 50     @Override
 51     protected void onCreate(Bundle savedInstanceState)
 52     {
 53         super.onCreate(savedInstanceState);
 54         setContentView(R.layout.activity_student_next_main);
 55         setSpinner();
 56     }
 57     public void pitcure(View view){
 58         screenshot();
 59     }
 60     private void screenshot()
 61     {
 62         // 獲取屏幕
 63         View dView = getWindow().getDecorView();  
 64         dView.setDrawingCacheEnabled(true);   
 65         dView.buildDrawingCache();   
 66         Bitmap bmp = dView.getDrawingCache();
 67         if (bmp != null)
 68         {
 69             try {
 70                 // 獲取內置SD卡路徑
 71                 String sdCardPath = Environment.getExternalStorageDirectory().getPath();
 72                 // 圖片文件路徑
 73                 String filePath = sdCardPath + File.separator + "screenshot.png";
 74                  
 75                 File file = new File(filePath);
 76                 FileOutputStream os = new FileOutputStream(file);
 77                 bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
 78                 os.flush();
 79                 os.close();
 80             } catch (Exception e) {
 81             }
 82         }
 83     }
 84     public void next(View view){
 85         Intent intent = new Intent(this,WriteMainActivity.class);
 86         startActivity(intent);
 87     }
 88     
 89     /*
 90      * 設置下拉框
 91      */
 92     private void setSpinner()
 93     {        
 94         projectsSpinner = (Spinner)findViewById(R.id.spin_projects);
 95         kindsSpinner = (Spinner)findViewById(R.id.spin_kinds);
 96         examinesSpinner = (Spinner)findViewById(R.id.spin_examines);
 97 
 98         //綁定適配器和值
 99         projectsAdapter = new ArrayAdapter<String>(StudentNextMainActivity.this,
100                 android.R.layout.simple_spinner_item, projects);
101         projectsSpinner.setAdapter( projectsAdapter);
102         projectsSpinner.setSelection(2,true);  //設置默認選中項,此處爲默認選中第3個值
103 
104         kindsAdapter = new ArrayAdapter<String>(StudentNextMainActivity.this, 
105                 android.R.layout.simple_spinner_item, kinds[2]);
106         kindsSpinner.setAdapter(kindsAdapter);
107         kindsSpinner.setSelection(0,true);  //默認選中第0個
108         examinesAdapter = new ArrayAdapter<String>(StudentNextMainActivity.this,
109                 android.R.layout.simple_spinner_item, examines[2][0]);
110         examinesSpinner.setAdapter(examinesAdapter);
111         examinesSpinner.setSelection(0, true);             
112         projectsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
113         {
114             // 表示選項被改變的時候觸發此方法,主要實現辦法:動態改變地級適配器的綁定值
115             @Override
116             public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3)
117             {
118                 
119                 kindsAdapter = new ArrayAdapter<String>(
120                 StudentNextMainActivity.this, android.R.layout.simple_spinner_item,kinds[position]);
121                 kindsSpinner.setAdapter(kindsAdapter);
122                 provincePosition = position;    //記錄當前省級序號,留給下面修改縣級適配器時用
123             }
124             @Override
125             public void onNothingSelected(AdapterView<?> arg0)
126             {
127 
128             }
129 
130         });
131 
132         
133         //種類下拉監聽
134         kindsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
135         {
136             @Override
137             public void onItemSelected(AdapterView<?> arg0, View arg1,
138                     int position, long arg3)
139             {
140                 examinesAdapter = new ArrayAdapter<String>(StudentNextMainActivity.this,
141                         android.R.layout.simple_spinner_item, examines[provincePosition][position]);
142                 examinesSpinner.setAdapter(examinesAdapter);
143             }
144             @Override
145             public void onNothingSelected(AdapterView<?> arg0)
146             {
147 
148             }
149         });
150     }
151 }
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="fill_parent"
 3     android:layout_height="fill_parent"
 4     android:orientation="vertical"     >
 5 <RelativeLayout
 6     android:layout_width="fill_parent"
 7     android:layout_height="50dp"
 8     android:background="#000000">
 9     <TextView 
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content"
12         android:textSize="24sp"
13         android:layout_centerInParent="true"
14         android:layout_centerHorizontal="true"
15         android:layout_centerVertical="true"
16         android:textColor="#FFFFFF"
17         android:text="學生綜合實踐模塊積分申請表"/>
18 </RelativeLayout>
19 <View 
20     android:layout_width="match_parent"
21     android:layout_height="8dp"/>
22 <LinearLayout 
23     android:layout_width="match_parent"
24     android:layout_height="wrap_content"
25    android:padding="8dp"
26     android:orientation="vertical">
27     <Spinner
28         android:id="@+id/spin_projects"
29         android:layout_width="150dp"
30         android:layout_height="wrap_content" />
31     <Spinner
32         android:id="@+id/spin_kinds"
33         android:layout_width="200dp"
34         android:layout_height="wrap_content" />
35     <Spinner
36         android:id="@+id/spin_examines"
37         android:layout_width="300dp"
38         android:layout_height="wrap_content" />
39 </LinearLayout>
40 <RelativeLayout 
41    android:layout_width="match_parent"
42     android:layout_height="wrap_content" >
43 
44     <Button
45         android:layout_width="wrap_content"
46         android:layout_height="wrap_content"
47         android:layout_alignParentRight="true"
48         android:layout_alignParentTop="true"
49         android:onClick="pitcure"
50         android:background="#FFFFFF"
51         android:textColor="#000000"
52         android:text="截圖" />
53 <Button
54         android:layout_width="wrap_content"
55         android:layout_height="wrap_content"        
56         android:onClick="next"
57         android:background="#FFFFFF"
58         android:textColor="#000000"
59         android:text="下一步" />
60     
61 </RelativeLayout>
62 
63 </LinearLayout>

以上代碼是實現這個界面的

 1 package com.itcast.test03;
 2 import android.os.Bundle;
 3 import android.app.Activity;
 4 import android.view.Menu;
 5 
 6 public class WriteMainActivity extends Activity {
 7 
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.activity_write_main);
12     }
13 
14     @Override
15     public boolean onCreateOptionsMenu(Menu menu) {
16         // Inflate the menu; this adds items to the action bar if it is present.
17         getMenuInflater().inflate(R.menu.write_main, menu);
18         return true;
19     }
20 
21 }
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     android:padding="8dp" >
 7     <RelativeLayout
 8        android:layout_width="match_parent"
 9          android:layout_height="50dp"
10          android:background="#000000"> 
11          <Button
12         android:id="@+id/upload"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:layout_alignParentRight="true"
16         android:layout_centerHorizontal="true"
17         android:layout_centerVertical="true"
18         android:textColor="#FFFFFF"
19         android:background="#000000"
20         android:textSize="18sp"
21         android:text="發送" />
22     </RelativeLayout>
23   
24 <LinearLayout
25     android:layout_width="match_parent"
26     android:layout_height="match_parent"
27     android:background="#ffffff"
28     android:orientation="vertical" >
29    <EditText
30         android:layout_width="fill_parent"
31         android:layout_height="100dp"
32         android:layout_margin="8dp"
33         android:gravity="left|top"
34         android:hint="填寫你要申請的分數及其餘信息......"       
35         android:background="@null" >
36     </EditText>
37     <ImageView 
38        android:layout_width="100dp"
39         android:layout_height="100dp"
40         android:src="@drawable/icon_addpic_unfocused"  />
41 
42     <GridView 
43         android:id="@+id/noScrollgridview"
44         android:layout_width="290dp"
45         android:layout_height="350dp"
46         android:layout_marginLeft="5dp"
47         android:horizontalSpacing="3dp"        
48         android:numColumns="4"
49         android:scrollbars="none"
50         android:verticalSpacing="5dp" >
51     </GridView>
52 
53 </LinearLayout>
54 </LinearLayout>

以上代碼是實現這個界面的

相關文章
相關標籤/搜索