學號 2017-2018-20172309 《程序設計與數據結構》實驗四報告
課程:《程序設計與數據結構》
班級: 1723
姓名: 王志偉
學號:20172309
實驗教師:王志強老師
實驗日期:2018年4月18日
必修/選修: 必修html
1、實驗內容
- 測試一:
Android Stuidio的安裝測試:
- 參考課本第24章,完成Android studio的安裝,
- 完成Hello World,按要求修改res目錄中內容,Hello World後要顯示本身的學號。
- 學習Android studio 調試應用程序
- 測試二:
Activity測試:
- 構建項目,運行相關代碼。
- 建立ThirdActivity, 在ThirdActivity中顯示本身的學號,修改代碼讓MainActivity啓動ThirdActivity
- 測試三:
UI測試:
- 構建項目,運行相關代碼。
- 修改代碼讓Toast信息中顯示本身的學號信息。
- 測試四:
佈局測試:
- 構建項目,運行相關代碼。
- 修改佈局,讓P290頁的界面與教材不一樣。
2、實驗過程及結果:
- 安裝Android studio:
首先下載Android studio
點擊下載
打開下載的安裝包,出現如圖所示頁面![](http://static.javashuo.com/static/loading.gif)
遇到此種狀況,點取消便可![](http://static.javashuo.com/static/loading.gif)
第一次運行可能會要求配置Android SDK(安裝過程當中要知道本身的SDK安裝到什麼地方了):![](http://static.javashuo.com/static/loading.gif)
- 完成程序Hello World:
好了之後出現如此頁面,點擊新創項目![](http://static.javashuo.com/static/loading.gif)
咱們先作最簡單的項目Hello World,注意項目地址在哪![](http://static.javashuo.com/static/loading.gif)
點擊Next 出現![](http://static.javashuo.com/static/loading.gif)
點擊phone or table(手機或者平板),點擊Next,出現![](http://static.javashuo.com/static/loading.gif)
點擊Empty Activity 一個新活動。
設置新活動的名字![](http://static.javashuo.com/static/loading.gif)
在layout裏面添加按鈕 以顯示Hello World。拖住1至位置2 在位置3可修改按鈕名稱。
![](http://static.javashuo.com/static/loading.gif)
運行結果:![](http://static.javashuo.com/static/loading.gif)
- 建立一個主活動,內含一個按鈕,按了就會出現第二個活動。
首先建立好活動後,在layout裏放置一個按鈕,以便調出活動二:
![](http://static.javashuo.com/static/loading.gif)
- 而後就能夠建立第二個活動了:我準備把上次作的進出棧做爲第二個活動頁面:
![](http://static.javashuo.com/static/loading.gif)
- 接下來就是編寫一段代碼做爲橋樑以把這兩個活動頁面串聯起來:
![](http://static.javashuo.com/static/loading.gif)
其中Intent intent = new Intent(活動頁面1,活動頁面2);
初始化一個對象把活動1和2鏈接起來,startActivity(intent);
表示爲啓動活動頁面。
4.出來後結果爲:
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
**注:一開始在活動一是按了按鈕就直接轉到活動二的,可是又在書中看到了AlertDialog,就把它添加到了這個項目中,因此我一開始是按照題幹作的,但願學長別扣分^_^**
- 測試三:
這個測試只須要在活動頁面中顯示一個Toast,所以我在代碼中添加了Toast.makeText(this, "20172309", Toast.LENGTH_SHORT).show();
就好了,
結果爲:![](http://static.javashuo.com/static/loading.gif)
- 測試四:
- 修改課本P290頁上的活動,以讓他們顯示不一樣:這一本分我認爲如今全部的UI組件均可以直接拖動,所以:我認爲就一個難點:框中的麥克風怎麼顯示:
![](http://static.javashuo.com/static/loading.gif)
我當時是這樣操做的:
![](http://static.javashuo.com/static/loading.gif)
在這個目錄下就能夠發現一個長得像麥克風的標誌。
- chapter28_MultiColorClock:
![](http://static.javashuo.com/static/loading.gif)
- chapter26_BaseComponent:
![](http://static.javashuo.com/static/loading.gif)
注意點:實現書中代碼有兩種方法:1.直接複製。2. 直接導入。
- 由於第一次是本身輸入加複製,老是出現許多麻煩,因此選擇了導入:導入的方法是依次點擊File——>Open——>要導入的項目。
- 第一次導入多是須要下載相關文件資源,因此特別慢,我的推薦使用熱點下載,我大概用了5~6分鐘。好了後電腦叫你安裝什麼你就安裝什麼。
- 大概會出現此樣頁面:
![](http://static.javashuo.com/static/loading.gif)
據說是應爲代碼太老,軟件版本太新。因此須要手動設置版本:
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
格式爲:更改前版本->更改後版本。改完後應該會變成這樣:![](http://static.javashuo.com/static/loading.gif)
以後咱們就能夠運行了。
3. 實驗過程當中遇到的問題和解決過程
所遇到的問題大概在上一環節已經表述,如今總結下:
測試一:
不知道
有什麼用。
TextView
爲一個顯示框,裏面的文本不能修改。
Button
爲一個按鈕,按鈕能夠修改爲本身想要的名字,需注意Id,id在代碼中將會便引用以便知道是哪一個button。id格式爲:button x (x=1 , 2 , 3 , ...)。若是想Text不全爲大寫時,在layout中加入android:textAllCaps = false
即不會全大寫了。
ImageView
一個能夠插入圖片的按鈕,圖片可使用自帶的,也可使用從網上下載的。
Plain Text
一個輸入框。
MultiLine Text
一個輸出框
.......
測試二:如何從一個活動跳轉到另外一個活動?java
- 新創一個活動
- 代碼實現先後兩個活動的連接:
> FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
> fab.setOnClickListener(new View.OnClickListener() {
> @Override
> public void onClick(View view) {
> Intent intent=new Intent(MainActivity.this,navigationactivity.class);
> startActivity(intent);
>
> }
> });
測試三:如何使用Toast?
發現一個很簡單的方法:在代碼中輸入Toast 再摁Tab會自動補齊:![](http://static.javashuo.com/static/loading.gif)
只須要修改Text內容。
測試4、測試五中出現的問題,已經在上面詳細寫出。python
收穫感悟
嗯,比較開心。由於本身可以弄出一個Android小程序了,雖然很簡單。不知道何時想起了小時候想出來的一個想法:製作一個QQ盜號軟件。哈哈哈 。如今好像出來了思路。先讓用戶輸入一個QQ郵箱,輸入後能夠打包生成一個軟件。只要輸入的密碼正確就會把密碼發到這個郵箱中去!!生成的軟件就是讓用戶輸入帳號密碼,而後登錄,若是密碼錯誤就顯示密碼錯誤,密碼正確就跳轉到一個頁面(頁面內容由這個盜號軟件的功能而定)同時用登錄成功的QQ把密碼發送到指定的QQ郵箱中去。
嗯,以爲本身小時候好幼稚,如今的能力達不到上述技術要求o(╥﹏╥)o。
android
參考資料
- 《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》
- Android 開發簡易教程
- 關於xmlns:android="http://schemas.android.com/apk/res/android的介紹
- match_parent的意思
- 啓動另外一個Activity