2023年Android实验一实验报告.docx
《2023年Android实验一实验报告.docx》由会员分享,可在线阅读,更多相关《2023年Android实验一实验报告.docx(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、A n droi d实验报告一姓名:丁军峰班级:信科123学号:08 1 2 3448a n d r o id:backgro u n d = # fffff ff fCmaReBut I ona n d r oid:i d = +id/id_ib_de le t e andr oid : la y ou t _w i dt h =r, ”a ndroid:layout_h c i ght= wr ap_ con tentand roid: layout_weig h t = 1 and roid :sr c =draMa b Le/ic_me nu_deLeteand roi d : bac
2、kground =为力方/手 fandroi d :o n Click=r,det eteltem/3.创建数据库pa c k a g e com.LIQI.Stuff;i mport android.c o n tent.Co n t ex t ;impo r tandro id.databa s e.s q lit e.SQL i t e Da t abase;im p orta n dr o id.databa s e.sq1 it e . S QLiteDatab a s e . CursorFacto ry:i mporta ndroid.data b a se. sq1 ite.
3、S QLiteOp e nH e Iper;public c 1a ssMySQLit e 0 p enHe I p er e x t e nds S Q L ite 0 penHelp er。 public M y SQLiteOpenH e IperfConte x t co n t e x t3) super(con t ext, LI Q I .db, null, 1);/ / TO D O Aut o ge n e rated c o ns t ructor s t ub )Ov e r ridepu b 1 i c vo i d onCr e ate( S QLi t eDatab
4、a s e db) o d b . e xecSQL( c re a t e table LI QI (Jd inte g erprimary ke y a u t oincrement , s t u f f,am o u n t ,p r ice);3 Ove r ridep u bl i c vo i d onUp g rade (SQL i t e Databas e db, int o Id Ve r s i o n, i n t n ewVers i on) 33/ TODO Au t o-generat e d method stub)4.创建a cco u nt类p a ck
5、a ge com. L I QI. Stu f f ;p ubli c clas s St u f f pri v ate St r i ng stu f f N a me;pr i vate int Stuf f Am o unt;p r i v a te flo a t S tuffP r ic e ;pu b lie Stri n g get S tu f f N a me() 3 ret urn stu f fName;public void s e tStuffName(S t ring s t u f fNam e ) ,t h i s . st u ffN a me = stuf
6、 f Nam e ;)pu blic i n t g etS t uffAmount() return Stuf f Am o un t ;p u bl i c void se t S t uff Amount(int stuff Amount) Stuff Amount = s t u ffAm o unt;)pub 1 i c float g e t St u ff Pric e ()r eturn St u ffPrice;)pub lie void se t Stu f fPri c e ( f loat s tuf f Price) St u ff Price = stuf f Pr
7、i c e;)5.创建数据操作逻辑pa c k a g e c o m.LIQ I .St u ff;i mp o rt java.ut i I. Array List;import java. util. List:i mport androi d .a p p .Activity;import a n d r oid.d a tab a se. C u r sor;import andr o id. d atabase. s q 1 ite. SQLit e Databa s e;i mport a nd r oid.os. Bundle;impo r t android, vie w.
8、Vie w ;impor t androi d . v iew. V iew. OnClickList e n e r;import a ndroid.view.Vie w G roup;impo r t a ndr o id. wi d get. BaseA d ap t er;import a ndroid.w i d ge t .ImageButt o n;import android.wi d get.lma g eView;i mport android.widget. L i s t V i e w;impo r t android. w i dget.Te x tVj e w:i
9、 mpo r t andr o id. w i dge t . To a s t;pu b I i c c la s s Stu ffLis t exte n ds A c tivit y pri v at e Li s t V i ew 1 v;o p ri v ate SQL i t eDa t abase mDa t aBa s e ;privat e L i s tstu f f I nfos;。p r ivate M y S Q Lite 0 penHelper mHelper; 0 ver rid ep r otect e d void o nCreat e (Bun d Ie s
10、 aved I nstan c eSt a t e) a setConten t V i ew(R. 1 ayout. s h ow_al 1 );mHel per =ne w MySQL i teOpenH e I p e r ( t h i s); 0lv=(ListView ) f i n dVi e wByld( R . id .id_lv);all(): su p er.o n C re a t e(sav e d I nst a nceS t a t e);)p u b lie void a 1 l()o mDataB a se = mH e I p er.getWritab 1
11、eD a t a b a s e (); 0 0a Cursor curs o r=mDataBa s e. q u eryCLlQI, null, null, nu 1 I, null, n u 1 I, nu 1 I):st u f fl n f o s=new A r r a yLi s t ();o wh i 1 e(c u r sor. moveToNe x t() ) a。S t u ff s t uff=n e w St u ff(); stu f f .sets t uf f N a me ( c ursor.getString(l);o。s t u ff.s e tStuff
12、Am o un t (cu r s or.g e tint (2);stuff.setStuffPri c e( c u r s o r .ge t Float(3): stuf f I n f o s .a d d (stuff);)cu r s o r .clos e ();o mData Bas e .close();o d v .setAd a pt e r ( new Myadapter();c 1 ass My a dapte r exte n ds BaseAdaptero Overr i d eo p u blic int getCoun t ) o r e turn stu
13、f flnfo s .s i ze();Oft)a 0v e r ri d e。public Ob j ect ge t Itemfint pos i tion) o / TODO Aut o ge n erate d metho d stubr etu r n null;0)Overri d eo public Ion g get I t em I d (i n t pos i ti o n ) 。/ T ODO Autog e n e rated m e tho d st u b。return 0;)。Ov e rride p u blic View g et V i ew(fina 1
14、int positi o n, Vi e w v i e w , Vi e wG r oup parent)v i ew = View.i n flate (S t u ff L i st.thi s , R. 1 ayo u t. s tuf f Jtem, n u 1 I);ooTextView t v_n am e = (TextV i ew) view . f ind Vi e wB y ld(R.id.id_tv_name);。 Te x tView t v_ a mount=(Tex t View)view . fi n d ViewByldf R.id.i d _tv_amoun
15、 t );Tex tView tv_p r i c e = (TextVie w) view . f in d V iewByld(R.i d .i d _ t v_pr iI m age B u t ton i Bu t t on = (ImageButto n ) vie w . f i n d V i ewByl d(R.id.id_ib_del e t e);o。tv_nam e. s e tText(stuff Infos.getfpos i t ion).g e tStu f fN a me ();。 tv_am o u n t . s e tText(数量(个)+stuffl n
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2023 Android 实验 报告
限制150内