太原理工軟件學(xué)院android上機(jī)實(shí)驗(yàn)_第1頁(yè)
太原理工軟件學(xué)院android上機(jī)實(shí)驗(yàn)_第2頁(yè)
太原理工軟件學(xué)院android上機(jī)實(shí)驗(yàn)_第3頁(yè)
太原理工軟件學(xué)院android上機(jī)實(shí)驗(yàn)_第4頁(yè)
太原理工軟件學(xué)院android上機(jī)實(shí)驗(yàn)_第5頁(yè)
已閱讀5頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

目錄實(shí)驗(yàn)一Android系統(tǒng)環(huán)境搭建 1實(shí)驗(yàn)二Activity運(yùn)用實(shí)驗(yàn) 4實(shí)驗(yàn)三android應(yīng)用UI設(shè)計(jì)〔一〕 5實(shí)驗(yàn)三android應(yīng)用UI設(shè)計(jì)〔二〕 7局部參考答案 9

實(shí)驗(yàn)一Android系統(tǒng)環(huán)境搭建一、目的與要求1.掌握Android環(huán)境的搭建。2.學(xué)會(huì)Java、eclipse、AndroidSDK以及ADT的安裝與環(huán)境變量設(shè)置。3.學(xué)會(huì)在線(xiàn)更新SDK。4.掌握離線(xiàn)安裝SDK的方法。二、實(shí)驗(yàn)內(nèi)容1.安裝JDK,SE6.0以上版本。⑴訪問(wèn)以下下載JDK。⑵配置環(huán)境變量:安裝J2SDK以后,假設(shè)需要在cmd下使用Java命令和編譯、運(yùn)行程序,可以配置環(huán)境變量:新建環(huán)境變量JAVA_HOME,右擊“我的電腦〞—>“屬性〞—>“高級(jí)〞—>“環(huán)境變量〞,如圖1-1所示:圖1-1⑶測(cè)試JDK安裝成功與否:編寫(xiě)test.java文件,運(yùn)行。要求:請(qǐng)將安裝的目錄與環(huán)境變量的配置圖粘到后面的空白頁(yè)上。并將test.java在運(yùn)行結(jié)果粘上。2.安裝eclipse。訪問(wèn)以下:///downloads/下載。選擇Windows平臺(tái)“EclipseIDEforJavaEEDevelopers〞下載,下載完成后,找到下載的壓縮包“eclipse-java-indigo-SR2-win32.zip〞,Eclipse無(wú)須安裝程序,解壓此壓縮文件到目標(biāo)文件即可。要求:請(qǐng)將安裝的目錄與eclipse環(huán)境的界面圖粘到后面的空白頁(yè)上。3.安裝AndroidSDK[1]訪問(wèn)以下網(wǎng)址下載:[2]在線(xiàn)安裝SDK:翻開(kāi)SDKManager,如圖1-2、1-3所示。圖1-2圖1-3[3]離線(xiàn)安裝:首先下載SDK的安裝包,“android-sdk_r16-windows.zip〞〔安裝工具〕解壓到目錄,如我的目錄D:\TDDOWNLOAD\android-sdk_r16-windows\android-sdk-windows,然后新建以下幾個(gè)文件夾:platforms,docs,samples,usb_driver,market_licensing。接著翻開(kāi)下載工具,下載以下內(nèi)容:ows.zip

要求:請(qǐng)將安裝的目錄與SDK在界面圖粘到后面的空白頁(yè)上。4.安裝ADT[1]首先啟動(dòng)Eclipse,選擇Help->InstallNewSoftware,翻開(kāi)Eclipse的插件安裝頁(yè)面。[2]單擊Add按鈕,彈出“AddRepository〞對(duì)話(huà)框,在Name中輸入:ADT,在Location中輸入:,單擊OK按鈕后,Eclipse會(huì)自動(dòng)搜索可安裝的插件。[3]此時(shí)Eclipse會(huì)搜索指定URI的資源,如果搜索無(wú)誤,會(huì)出現(xiàn):DevelopTools的復(fù)選框,選中復(fù)選框,點(diǎn)擊“Next〞按鈕。再點(diǎn)擊finish按鈕[4]整個(gè)安裝過(guò)程會(huì)持續(xù)幾分鐘,安裝結(jié)束后會(huì)出現(xiàn)Eclipse重啟提示界面,。建議選擇“RestartNow〞按鈕重新啟動(dòng)Eclipse,使ADT插件生效。[5]在ADT插件安裝完畢且重啟Eclipse之后,進(jìn)入配置Android開(kāi)發(fā)環(huán)境的最后一步,設(shè)置AndroidSDK的位置。首先選擇Windows->Preference命令翻開(kāi)Eclipse的配制界面,然后在SDKLocation中輸入AndroidSDK的保存路徑,最后單擊OK按鈕使配置生效。要求:請(qǐng)將安裝ADT后的eclipse界面圖粘到后面的空白頁(yè)上。

實(shí)驗(yàn)二Activity運(yùn)用實(shí)驗(yàn)一、目的與要求1.熟悉Activity與Intent的使用。2.掌握Activity啟動(dòng)另一個(gè)Activity的方法。3.會(huì)使用Intent對(duì)象進(jìn)行Activity間意圖的傳達(dá)。二、實(shí)驗(yàn)內(nèi)容1.編一Android應(yīng)用程序TestActivity01,使用MainActivity,啟動(dòng)另一個(gè)OtherActivity。MainActivity主界面上只有一個(gè)按鈕。OtherActivity上只有一個(gè)TextView組件。要求:請(qǐng)將工程中的MainActivity.java,OtherActivity.java以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。2.編一Android應(yīng)用程序TestActivity02,使用MainActivity,啟動(dòng)另一個(gè)OtherActivity。MainActivity主界面上只有一個(gè)按鈕。OtherActivity上只有一個(gè)TextView組件。要將MainActivity中的數(shù)據(jù)“中國(guó)〞通過(guò)Intent對(duì)象傳到OtherActivity上顯示。要求:請(qǐng)將工程中的MainActivity.java,OtherActivity.java以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。

實(shí)驗(yàn)三android應(yīng)用UI設(shè)計(jì)〔一〕一、目的與要求1.熟悉TextView、Button、ImageView、LinearLayout、TabelLayout、RelativeLayout、FrameLayout、AlertDialog對(duì)話(huà)框。2.掌握以上UI設(shè)計(jì)元素的根本功能和用法。3.掌握UI設(shè)計(jì)的根本方法。二、實(shí)驗(yàn)內(nèi)容〔一〕實(shí)現(xiàn)一個(gè)如圖3.1所示的UI界面1.布局分析:最外層是縱向的線(xiàn)性布局〔LinearLayout,android:orientation="vertical"〕,包含了三個(gè)布局,橫向的線(xiàn)性布局〔四列〕、表格布局〔TableLayout,三行三列〕、縱向的線(xiàn)性布局〔四行〕。2.在res\layout文件夾下的MyLayout.xml中實(shí)現(xiàn)。3.布局內(nèi)的控件為T(mén)extView要求:請(qǐng)將工程中的java源文件以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。圖3.1布局嵌套圖3.2多輸入對(duì)話(huà)框

〔二〕實(shí)現(xiàn)一個(gè)如圖3.2所示的多輸入框的對(duì)話(huà)框1.要求使用LinearLayout布局、TextView、EditText控件各兩個(gè)。2.要求點(diǎn)擊按鈕后有對(duì)應(yīng)的輸出〔用Toast控件、TextView控件以及Logcat窗口輸出都可以〕。要求:請(qǐng)將工程中的java源文件以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。

實(shí)驗(yàn)三android應(yīng)用UI設(shè)計(jì)〔二〕一、目的與要求1.熟悉Menu、Toast、Notification等UI元素。2.掌握以上UI設(shè)計(jì)元素的根本功能和用法。3.掌握以上UI設(shè)計(jì)的根本方法與框架。4.了解PendingIntent對(duì)象與Notification間的關(guān)系。5.了解根本的ListViewAdapter的設(shè)置與作用。二、實(shí)驗(yàn)內(nèi)容〔一〕在ListActivity中實(shí)現(xiàn)ContextMenu。1.編寫(xiě)上下文菜單實(shí)現(xiàn)如下功能:1〕用ArrayAdapter實(shí)現(xiàn)一個(gè)ListView,如圖4.1所示。2〕在每一表項(xiàng)上長(zhǎng)按后,彈出上下文菜單,如圖4.2所示。2.提示如下:1〕MainActivity從ListActivity派生而來(lái)〔便于對(duì)List在操作〕。2〕在onCreate中使用simpleShowList()方法顯示列表,并實(shí)現(xiàn)該方法。3〕為所有列表項(xiàng)注冊(cè)上下文菜單registerForContextMenu(getListView())。4〕不對(duì)上下文菜單做事件響應(yīng)〔代碼中僅表達(dá)框架就可以〕。要求:請(qǐng)將工程中的java源文件以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。圖4.1列表顯示圖4.2與列表相關(guān)的上下文菜單

〔二〕Notification1.實(shí)現(xiàn)一個(gè)如圖4.3如所的Notification。在點(diǎn)擊“發(fā)起通知〞按鈕后,在狀態(tài)欄出現(xiàn)圖標(biāo)與“我的通知〞信息。2.提示:1〕需要?jiǎng)?chuàng)立一個(gè)PendingIntent對(duì)象。該對(duì)象由Android系統(tǒng)負(fù)責(zé)維護(hù),因此,在應(yīng)用程序關(guān)閉后,該對(duì)象仍然不會(huì)被釋放。2〕點(diǎn)擊通知后由Intent(MainActivity.this,

NActivity.class)起動(dòng)下一個(gè)Activity。3〕NActivity僅顯示一個(gè)TextView就可以,其內(nèi)容為“Notification啟動(dòng)成功〞。要求:請(qǐng)將工程中的java源文件以及對(duì)應(yīng)的xml文件源碼附上。同時(shí)將運(yùn)行的界面圖粘上。圖4.3通知的界面

局部參考答案實(shí)驗(yàn)3參考答案〔一〕1、布局配置文件main.xml<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="://schemas.android/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_weight="4">

<TextView

android:text="red"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ff0000"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="green"

android:textSize="7pt"

android:textColor="#000000"

android:background="#00ff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="blue"

android:textSize="7pt"

android:textColor="#000000"

android:background="#0000ff"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="yellow"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ffff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_weight="1">

<TableLayoutxmlns:android="://schemas.android/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1">

<!--拉伸指定列來(lái)填滿(mǎn)父控件-->

<TableRow

android:id="@+id/row1"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<TextView

android:text="@string/row1_column1"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row1_column2"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row1_column3"

android:gravity="center_horizontal"

android:padding="3dip"

/>

</TableRow>

<TableRow

android:id="@+id/row2"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<TextView

android:text="@string/row2_column1"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row2_column2"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row2_column3"

android:gravity="center_horizontal"

android:padding="3dip"

/>

</TableRow>

<TableRow

android:id="@+id/row3"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<TextView

android:text="@string/row3_column1"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row3_column2"

android:gravity="center_horizontal"

android:padding="3dip"

/>

<TextView

android:text="@string/row3_column3"

android:gravity="center_horizontal"

android:padding="3dip"

/>

</TableRow>

</TableLayout>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_weight="2">

<TextView

android:text="red"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ff0000"

android:gravity="center_vertical|center_horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="green"

android:textSize="7pt"

android:textColor="#000000"

android:background="#00ff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="blue"

android:textSize="7pt"

android:textColor="#000000"

android:background="#0000ff"

android:gravity="center_vertical|center_horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

<TextView

android:text="yellow"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ffff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

</LinearLayout></LinearLayout>===================================2、string.xml文件<?xmlversion="1.0"encoding="utf-8"?><resources>

<stringname="hello">HelloWorld,ComplicateLayout!</string>

<stringname="app_name">Layout04</string>

<stringname="row1_column1">學(xué)號(hào)</string>

<stringname="row1_column2">姓名</string>

<stringname="row1_column3">性別</string>

<stringname="row2_column1">10101</string>

<stringname="row2_column2">李剛</string>

<stringname="row2_column3">男</string>

<stringname="row3_column1">10102</string>

<stringname="row3_column2">文靜</string>

<stringname="row3_column3">女</string></resources>=================================3、Android工程清單文件<?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="://schemas.android/apk/res/android"

package="hw.layout04"

android:versionCode="1"

android:versionName="1.0">

<uses-sdkandroid:minSdkVersion="8"/>

<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name">

<activity

android:name="plicateLayout"

android:label="@string/app_name">

<intent-filter>

<actionandroid:name="ent.action.MAIN"/>

<categoryandroid:name="ent.category.LAUNCHER"/>

</intent-filter>

</activity>

</application></manifest>==================================4、Java源程序packagehw.layout04;importandroid.app.Activity;importandroid.os.Bundle;publicclassComplicateLayoutextendsActivity{

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}}〔二〕需要一個(gè)布局01<?xmlversion="1.0"encoding="utf-8"?>02<LinearLayoutxmlns:android="://schemas.android/apk/res/android"03android:layout_width="fill_parent"04android:layout_height="fill_parent"05android:orientation="vertical">07<TextView08android:id="@+id/textView1"09android:layout_width="wrap_content"10android:layout_height="wrap_content"11android:text="姓名"/>13<EditText14android:id="@+id/editTextName"15android:layout_width="match_parent"16android:layout_height="wrap_content">18<requestFocus/>19</EditText>21<TextView22android:id="@+id/textView2"23android:layout_width="wrap_content"24android:layout_height="wrap_content"25android:text="號(hào)碼"/>27<EditText28android:id="@+id/editTextNum"29android:layout_width="match_parent"30android:layout_height="wrap_content"/>32</LinearLayout>//代碼01protectedvoidshowAddDialog(){03LayoutInflaterfactory=LayoutInflater.from(this);04finalViewtextEntryView=factory.inflate(R.layout.dialog,null);05finalEditTexteditTextName=(EditText)textEntryView.findViewById(R.id.editTextName);06finalEditTexteditTextNumEditText=(EditText)textEntryView.findViewById(R.id.editTextNum);07AlertDialog.Builderad1=newAlertDialog.Builder(FriendActivity.this);08ad1.setTitle("增加聯(lián)系人:");09ad1.setIcon(android.R.drawable.ic_dialog_info);10ad1.setView(textEntryView);11ad1.setPositiveButton("是",newDialogInterface.OnClickListener(){12publicvoidonClick(DialogInterfacedialog,inti){14Log.i("111111",editTextName.getText().toString());15PersonServicepersonService=newPersonService(16FriendActivity.this.getBaseContext());17Personperson=newPerson();18person.setName(editTextName.getText().toString());19person.setPhoneNumber(editTextNumEditText.getText().toString());20personService.save(person);22}23});24ad1.setNegativeButton("否",newDialogInterface.OnClickListener(){25publicvoidonClick(DialogInterfacedialog,inti){27}});ad1.show();//顯示對(duì)話(huà)框}實(shí)驗(yàn)4參考答案〔一〕//注冊(cè)上下文菜單PublicclassSampleContextMenuActivityextendsListActivity{privatestaticfinalStringTAG="SampleContextMenuActivity";@OverrideProtectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//顯示列表simpleShowList();//為所有列表項(xiàng)注冊(cè)上下文菜單this.registerForContextMenu(getListView());}PrivatevoidsimpleShowList(){//listitemString[]files=newString[]{"文件1","文件2","文件3","文件4"};//simplearrayadapterArrayAdapter<String>adapter=newArrayAdapter<String>(this,android.R.layout.simple_list_item_1,files);//setadapterthis.setListAdapter(adapter);Log.v(TAG,"showsimplelist");}}//生成上下文菜單@Override

publicvoidonCreateContextMenu(ContextMenumenu,Viewv,

ContextMenuInfomenuInfo){

Log.v(TAG,"populatecontextmenu");

//setcontextmenutitle

menu.setHeaderTitle("文件操作");

//addcontextmenuitem

menu.add(0,1,Menu.NONE,"發(fā)送");

menu.add(0,2,Menu.NONE,"標(biāo)記為重要");

menu.add(0,3,Menu.NONE,"重命名");

menu.add(0,4,Menu.NONE,"刪除");

}//響應(yīng)上下文菜單項(xiàng)@Override

publicbooleanonContextItemSelected(MenuItemitem){

//得到當(dāng)前被選中的item信息

AdapterContextMenuInfomenuInfo=(Adap

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論