【正文】
} } The first difference is that rather than setting the content view to be a view we created in Java code, we set it to reference the XML layout (setContentView()). The source file will be updated when we rebuild this project to include a reference to our layout file (stored as in our project’s res/layout directory). The other difference is that we need to get our hands on our Button instance, for which we use the findViewById() call. Since we identified our button as +id/button, we can reference the button’s identifier as . Now, with the Button instance in hand, we can set the callback and set the label as needed. As you can see in Figure 51, the results look the same as with the original Now demo. Figure 51. The NowRedux sample activityEmploying Basic WidgetsEvery GUI toolkit has some basic widgets: fields, labels, buttons, etc. Android’s toolkit is no different in scope, and the basic widgets will provide a good introduction as to how widgets work in Android 。 } public void onClick(View view) { updateTime()。(this)。 setContentView()。 public class NowRedux extends Activity implements { Button btn。 import 。 import 。 This is the same setContentView() we used earlier, passing it an instance of a View subclass (in that case, a Button). The Androidbuilt view, constructed from our layout, is accessed from that codegenerated R class. All of the layouts are accessible under , keyed by the base name of the layout file— results in . To access our identified widgets, use findViewById(), passing in the numeric identifier of the widget in question. That numeric identifier was generated by Android in the R class as (where something is the specific widget you are seeking). Those widgets are simply subclasses of View, just like the Button instance we created in Chapter 4. The Rest of the Story In the original Now demo, the button’s face would show the current time, which would reflect when the button was last pushed (or when the activity was first shown, if the button had not yet been pushed). Most of that logic still works, even in this revised demo (NowRedux). However, rather than instantiating the Button in our activity’s onCreate() callback, we can reference the one from the XML layout: package 。同時(shí),我也衷心的感謝太原理工大學(xué)軟件學(xué)院四年來對我的精心栽培,為我進(jìn)入社會(huì)提供了莫大的幫助。在畢業(yè)設(shè)計(jì)期間,同學(xué)的幫助更是我能完成的重要因素,要對我親愛的同學(xué),說聲謝謝,并希望他們能在未來的道路上,越走越好。在項(xiàng)目初期對我們的幫助和指導(dǎo),使我們迅速確定了方向并明確了分工,以及在寫論文的過程中給的寶貴的意見。FifthPressman,《SoftwareO’Reilly.《JAVA APPLICATION》.電子工業(yè)出版社, [4] [M].人民郵電出版社,2009,7.[5] 靳巖,姚尚朗. Google Android開發(fā)入門與實(shí)戰(zhàn)[M].人民郵電出版社,[6] ,2011年01月12日[7] Michael . 輕松搞定XML 林嘉勝譯,2001年01月08日[8](英)Herbert Schildt Java參考大全(J2SE 5 Edition),清華大學(xué)出版社[9] 王向輝,張國印,2010年3月[10] RogerCerami。,當(dāng)點(diǎn)擊時(shí)可以切換到另一種效果。 進(jìn)一步工作的打算存在的問題:。腳踏實(shí)地,認(rèn)真嚴(yán)謹(jǐn),實(shí)事求是的學(xué)習(xí)態(tài)度,不怕困難、堅(jiān)持不懈、吃苦耐勞的精神是我在這次設(shè)計(jì)中最大的收益。Android開發(fā)的知識(shí)面廣而精,使我在整個(gè)畢業(yè)設(shè)計(jì)過程中,受益匪淺。在我徜徉書海查找資料的日子里,面對許多書本的羅列,最難忘的是每次找到資料時(shí)的激動(dòng)和興奮;親手每一個(gè)界面的時(shí)間里,記憶最深的是每一步小小思路實(shí)現(xiàn)時(shí)那幸福的心情。在論文中我充分地運(yùn)用了大學(xué)期間所學(xué)到的知識(shí)和最新用到的知識(shí)?;叵脒@段日子的經(jīng)歷和感受,我感慨萬千,在這次畢業(yè)設(shè)計(jì)的過程中,我擁有了無數(shù)難忘的回憶和收獲。從最初的茫然,到慢慢的進(jìn)入狀態(tài),再到對思路逐漸的清晰,整個(gè)寫作過程難以用語言來表達(dá)。測試結(jié)果基本符合預(yù)期。在模擬器主界面點(diǎn)擊menu后,再點(diǎn)擊add,進(jìn)入widget選擇對話框選擇該程序圖標(biāo)是否在主界面顯示。測試結(jié)果:點(diǎn)擊學(xué)習(xí)按鈕后進(jìn)入了用戶單詞學(xué)習(xí)界面,該界面上方顯示未學(xué)習(xí)的list和所有的list,中間顯示未學(xué)習(xí)的list列表。測試用例2:界面切換。在用戶主界面點(diǎn)擊詞庫選擇欄是否彈出用戶選擇對話框,點(diǎn)擊某一詞庫該界面的內(nèi)容顯示欄等是否發(fā)生變化。通過把軟件運(yùn)行在模擬器,然后進(jìn)行一下以上流程模擬的操作,再拿真機(jī)進(jìn)行一定的測試,包含以上流程的處理操作。本畢業(yè)設(shè)計(jì)主要測試各個(gè)界面切換是否正常、界面內(nèi)控件是否在操作之后做出相應(yīng)的反應(yīng)。在執(zhí)行測試的用例之后,根據(jù)需要跟蹤檢測到的故障,以保證開發(fā)的產(chǎn)品適合需求。 最后還要說一點(diǎn)的是,android中每一個(gè)Activity(顯示界面類) 系統(tǒng)最主要的配置文件中進(jìn)行注冊,才可以顯示該界面,否則系統(tǒng)將報(bào)異常。 //獲取intent中的Bundle對象key = (key)。第一個(gè)Activity獲取第一個(gè)Activity的數(shù)據(jù)代碼如下: Intent intent = ()。//以鍵值對的形式 (b)。 Bundle b=new Bundle()。Intent可用于從一個(gè)Activity轉(zhuǎn)到另一個(gè)Activity,還可以啟動(dòng)服務(wù)(在此不作介紹)。編輯單詞中,().toString().equals()().toString().equals()進(jìn)行單詞的匹配:非空判斷與單詞存在判斷,().toString().equals((i).getSpelling())。 ........... }點(diǎn)擊某個(gè)生詞后,生成一個(gè)dialog對象,然后顯示這個(gè)dialog。 (, )。 (action, add)。生詞本界面與編輯生詞本界面分別如圖47,圖48所示: 圖47 生詞本界面 圖48 編輯生詞本界面該生詞本模塊通過onCreateOptionsMenu(Menu menu)實(shí)現(xiàn)按下menu鍵后進(jìn)行添加新單詞,onOptionsItemSelected(MenuItem item)為單詞添加操作,相關(guān)代碼如下:public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { switch(()){ case MENU_ADD:{ Intent intent = new Intent()。按下編輯該單詞時(shí),進(jìn)入編輯生詞本界面。(ListView),文本框?yàn)樯~本,使用列表控件包含用戶所加入生詞本中的生詞,顯示單詞與單詞解釋。}break。 DisplayToast(正確)。} break。 DisplayToast (正確)。相關(guān)核心代碼如下:() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (isCheck) { isCheck = false。用戶單詞測試界面如圖46所示:圖46 用戶單詞測試界面用戶選擇單選框后系統(tǒng)進(jìn)行判斷,錯(cuò)誤給出正確解釋,正確進(jìn)入下一個(gè)。界面底部顯示三個(gè)按鈕,構(gòu)成一個(gè)線性布局。界面中間顯示一個(gè)文本框和一個(gè)單選鈕組(RadioGroup),構(gòu)成線性布局。(ListView),文本框?yàn)檫x擇測試單元,使用列表控件包含所選詞庫所有的list并顯示最高正確率。}}).create()。 (, )。 finish()。((currentnum).getSpelling(), null)。相關(guān)核心代碼如下:private void UpdateView() { if (currentnum()){ SharedPreferences setting = getSharedPreferences(, MODE_PRIVATE)。用戶在復(fù)習(xí)選擇時(shí)通過setVisibility()實(shí)現(xiàn)各個(gè)按鈕控件的可見與否。該單詞復(fù)習(xí)模塊首先需要對已學(xué)習(xí)過的list進(jìn)行數(shù)據(jù)存儲(chǔ),這里使用Activity類的getSharedPreferences方法獲得SharedPreferences對象,其中存儲(chǔ)keyvalue的文件的名稱由getSharedPreferences方法的第一個(gè)參數(shù)指定;。用戶單詞復(fù)習(xí)界面如圖45所示:圖45 用戶單詞復(fù)習(xí)界面按下我記得按鈕文本框顯示單詞的解釋,界面下方顯示“記對了”“記錯(cuò)了”兩個(gè)按鈕,按下記對了進(jìn)入下一個(gè)單詞的復(fù)習(xí)。界面底部顯示三個(gè)按鈕,另有兩個(gè)隱藏按鈕,構(gòu)成一個(gè)線性布局。界面中間顯示一個(gè)圖片按鈕和兩個(gè)文本框,構(gòu)成線性布局嵌套。} 用戶單詞復(fù)習(xí)模塊的實(shí)現(xiàn)。 if ((loc) == ){ (loc)。發(fā)音完成后,回收TTS即可,當(dāng)確定應(yīng)用程序不再需要TTS的相關(guān)功能后,可以在Activity的OnDestroy()()釋放當(dāng)前TTS實(shí)體所占用的資源。該學(xué)習(xí)模塊的機(jī)器發(fā)音功能通過TTS引擎實(shí)現(xiàn),TTS即TextToSpeech,將所指定的文本轉(zhuǎn)成不同語言音頻輸出。按鈕分別為:上一個(gè),加入生詞本,下一個(gè)。圖片按鈕為發(fā)音標(biāo)示,按鈕的屬性設(shè)置為android:drawable/btn_default,文本框分別為拼寫(spelling)與單詞解釋(info)。用戶單詞學(xué)習(xí)列表界面如圖43所示:圖43 用戶單詞學(xué)習(xí)列表界面:單詞記憶。studyword_main.xml文件里顯示兩個(gè)文本框,構(gòu)成一個(gè)框架布局FrameLayout。} (new ArrayAdapterString(this, , fileNames))。i。 fileNames = new String[]。 File f = new File(/sdcard/)。 ()。相關(guān)代碼如下: (savedInstanceState)。, Book2, Book3組成, ListAdapter(new ArrayAdapterString(this, , fileNames))。同時(shí)該界面initWidgets() 實(shí)現(xiàn)了桌面小插件的設(shè)置,把用戶生詞本的內(nèi)容直接呈現(xiàn),方便用戶的瀏覽。(adapter)。代碼如下:ArrayAdapter CharSequence adapter = new ArrayAdapter CharSequence (this, , books)。這些控件在一起采用相對布局,可以使這些控件的位置相對擺放,靠在父容器下方,不至于零