Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告_第1頁
Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告_第2頁
Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告_第3頁
Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告_第4頁
Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第1頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第1頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第2頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第2頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第3頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第3頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第4頁。ndroid實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第4頁。Android實(shí)驗(yàn)報(bào)告一姓名:丁軍峰班級(jí):信科12-3Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第5頁。學(xué)號(hào):08123448Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第5頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第6頁。Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第6頁。實(shí)驗(yàn)內(nèi)容編寫一個(gè)Android應(yīng)用程序,實(shí)現(xiàn)對(duì)自己物品的管理,功能包括添加、刪除和查詢等實(shí)驗(yàn)?zāi)康牧私鈇ndroid開發(fā)流程,掌握SQLite數(shù)據(jù)庫和ListView控件的使用需求分析使用SQLite數(shù)據(jù)庫,使用ListView控件顯示物品實(shí)驗(yàn)過程創(chuàng)建程序,設(shè)計(jì)用戶交互界面<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第7頁。android:layout_height="0dp"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第7頁。android:layout_weight="1"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="物品清單"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="物品名稱"/><EditTextandroid:id="@+id/id_et_stuffname"android:layout_width="match_parent"android:layout_height="wrap_content"android:inputType="text"/></LinearLayout><LinearLayoutAndroid實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第8頁。android:layout_width="match_parent"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第8頁。android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="物品個(gè)數(shù)"/><EditTextandroid:id="@+id/id_et_stuffamount"android:layout_width="match_parent"android:layout_height="wrap_content"android:inputType="text"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="物品價(jià)格"/><EditTextandroid:id="@+id/id_et_stuffprize"android:layout_width="match_parent"android:layout_height="wrap_content"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第9頁。android:inputType="text"/>Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第9頁。</LinearLayout></LinearLayout><FrameLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><Buttonandroid:id="@+id/id_bt_add"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="添加記錄"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="6dp"android:layout_marginBottom="7dp"android:gravity="center"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第10頁。android:padding="5dp"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第10頁。android:textColor="#727272"android:background="@drawable/recordbutton"android:minHeight="0dp"/><Buttonandroid:id="@+id/id_bt_all"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="顯示全部"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="6dp"android:layout_marginBottom="7dp"android:gravity="center"android:padding="5dp"android:textColor="#727272"android:background="@drawable/recordbutton"android:minHeight="0dp"/></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="#eee"/>Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第11頁。</FrameLayout>Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第11頁。</LinearLayout>2.創(chuàng)建ListViewItem布局<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"android:background="#ffffffff"><ImageViewandroid:id="@+id/id_ig_name"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:src="@drawable/ic_menu_paste_holo_light"/><TextViewandroid:id="@+id/id_tv_name"android:layout_width="0dp"android:layout_height="wrap_content"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第12頁。android:layout_weight="1"Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第12頁。android:textColor="#000000"android:textSize="18sp"/><TextViewandroid:id="@+id/id_tv_amount"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:textColor="#000000"android:textSize="18sp"/><TextViewandroid:id="@+id/id_tv_price"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:textColor="#000000"android:textSize="18sp"/><ImageButtonandroid:id="@+id/id_ib_delete"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:src="@drawable/ic_menu_delete"android:background="#ffffffff"android:onClick="deleteItem"/>Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第13頁。</LinearLayout>Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第13頁。3.創(chuàng)建數(shù)據(jù)庫packagecom.LIQI.Stuff;importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteDatabase.CursorFactory;importandroid.database.sqlite.SQLiteOpenHelper;publicclassMySQLiteOpenHelperextendsSQLiteOpenHelper{ publicMySQLiteOpenHelper(Contextcontext ){ super(context,"LIQI.db",null,1); //TODOAuto-generatedconstructorstub } @Override publicvoidonCreate(SQLiteDatabasedb){ db.execSQL("createtableLIQI(_idintegerprimarykeyautoincrement,stuff,amount,price)"); } @OverrideAndroid實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第14頁。 publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第14頁。 //TODOAuto-generatedmethodstub }}4.創(chuàng)建account類packagecom.LIQI.Stuff;publicclassStuff{privateStringstuffName;privateintStuffAmount;privatefloatStuffPrice;publicStringgetStuffName(){ returnstuffName;}publicvoidsetStuffName(StringstuffName){ this.stuffName=stuffName;}publicintgetStuffAmount(){ returnStuffAmount;}publicvoidsetStuffAmount(intstuffAmount){ StuffAmount=stuffAmount;Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第15頁。}Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第15頁。publicfloatgetStuffPrice(){ returnStuffPrice;}publicvoidsetStuffPrice(floatstuffPrice){ StuffPrice=stuffPrice;}}5.創(chuàng)建數(shù)據(jù)操作邏輯packagecom.LIQI.Stuff;importjava.util.ArrayList;importjava.util.List;importandroid.app.Activity;importandroid.database.Cursor;importandroid.database.sqlite.SQLiteDatabase;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.ImageButton;importandroid.widget.ImageView;Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第16頁。importandroid.widget.ListView;Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第16頁。importandroid.widget.TextView;importandroid.widget.Toast;publicclassStuffListextendsActivity{ privateListViewlv; privateSQLiteDatabasemDataBase; privateList<Stuff>stuffInfos; privateMySQLiteOpenHelpermHelper;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){ setContentView(R.layout.show_all); mHelper=newMySQLiteOpenHelper(this); lv=(ListView)findViewById(R.id.id_lv); all(); super.onCreate(savedInstanceState);}publicvoidall(){ mDataBase=mHelper.getWritableDatabase(); Cursorcursor=mDataBase.query("LIQI",null,null,null,null,null,null); stuffInfos=newArrayList<Stuff>(); while(cursor.moveToNext()){ Stuffstuff=newStuff();Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第17頁。 stuff.setStuffName(cursor.getString(1));Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第17頁。 stuff.setStuffAmount(cursor.getInt(2)); stuff.setStuffPrice(cursor.getFloat(3)); stuffInfos.add(stuff); } cursor.close(); mDataBase.close(); lv.setAdapter(newMyadapter()); } classMyadapterextendsBaseAdapter{ @Override publicintgetCount(){ returnstuffInfos.size(); } @Override publicObjectgetItem(intposition){ //TODOAuto-generatedmethodstub returnnull; }Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第18頁。 @OverrideAndroid實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第18頁。 publiclonggetItemId(intposition){ //TODOAuto-generatedmethodstub return0; } @Override publicViewgetView(finalintposition,Viewview,ViewGroupparent){ view=View.inflate(StuffList.this,R.layout.stuff_item,null); TextViewtv_name=(TextView)view.findViewById(R.id.id_tv_name); TextViewtv_amount=(TextView)view.findViewById(R.id.id_tv_amount); TextViewtv_price=(TextView)view.findViewById(R.id.id_tv_price); ImageButtoniButton=(ImageButton)view.findViewById(R.id.id_ib_delete); tv_name.setText(stuffInfos.get(position).getStuffName()); tv_amount.setText("數(shù)量(個(gè))"+stuffInfos.get(position).getStuffAmount()); tv_price.setText("單價(jià)(元)"+stuffInfos.get(position).getStuffPrice());iButton.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ mDataBase=mHelper.getWritableDatabase();Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第19頁。 mDataBase.delete("LIQI","stuff=?",newString[]{stuffInfos.get(position).getStuffName()});Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第19頁。 mDataBase.close(); stuffInfos.remove(position); Myadapter.this.notifyDataSetChanged(); } }); returnview; } }}6.編寫界面交互代碼packagecom.LIQI.Stuff;importandroid.app.Activity;importandroid.content.ContentValues;importandroid.content.Intent;importandroid.database.sqlite.SQLiteDatabase;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第20頁。importandroid.widget.Toast;Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第20頁。publicclassMainActivityextendsActivityimplementsOnClickListener{privateMySQLiteOpenHelpermHelper;privateSQLiteDatabasemDataBase;privateButtonbt_add,bt_all;privateEditTextet_stuffName,et_stuffAmount,et_stuffPrice; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.add_data); mHelper=newMySQLiteOpenHelper(this); initView(); initAction(); }publicvoidinitView(){ et_stuffName=(EditText)findViewById(R.id.id_et_stuffname); et_stuffAmount=(EditText)findViewById(R.id.id_et_stuffamount); et_stuffPrice=(EditText)findViewById(R.id.id_et_stuffprize); bt_add=(Button)findViewById(R.id.id_bt_add); bt_all=(Button)findViewById(R.id.id_bt_all);}Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第21頁。 Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第21頁。 publicvoidinitAction(){ bt_add.setOnClickListener(this); bt_all.setOnClickListener(this); } @Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.id_bt_add: add(); break; caseR.id.id_bt_all: Intentintent=newIntent(this,StuffList.class); startActivity(intent); break; } } publicvoidadd(){ StringstuffName=et_stuffName.getText().toString().trim();Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第22頁。 intstuffAmount=Integer.parseInt(et_stuffAmount.getText().toString().trim());Android實(shí)驗(yàn)一實(shí)驗(yàn)報(bào)告全文共26頁,當(dāng)前為第22頁。 floatstuffPrice=Float.parseFloat(et_stuffPrice.getText().toString().trim()); Stuffstuff=newStuff(); stuff.setStuffName(stuffName); stuff.setStuffAmount(stuffAmount); stuff.setStuffPrice(stuffPrice); mDataBase=mHelper.getWritableDatabase(); ContentValuescontentValues=newContentValues(); contentValues.put("stuff",stuff.getStuffName()); contentValues.put("amount",stuff.g

溫馨提示

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

評(píng)論

0/150

提交評(píng)論