




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验 简易新闻客户2、初步掌握Android1、HTTP2、HttpPost相同tab1.xmlandroid:layout_height="match_parent"><?xmlversion="1.0"11‐26"android:singleLine="true"publicclassCategoryimplementsprivateintid;privateStringcid;privateStringcname;publicintgetId(){return}publicvoidsetId(intid)this.id=}publicStringgetCid()return}publicvoidsetCid(Stringcid)this.cid=}publicStringgetCname()return}publicvoidsetCname(Stringcname)ame=}}publicclassNewsimplementsprivateintnid;privateStringtitle;privateStringexpress;privateStringcontent;privateStringdatetime;privateStringauthor;privateStringcid;publicintgetNid(){return}publicvoidsetNid(intnid)this.nid=}publicStringgetTitle()return}publicvoidsetTitle(Stringtitle)this.title=}publicStringgetContent()return}publicvoidsetContent(Stringcontent)this.content=}publicStringgetDatetime()return}publicvoidsetDatetime(Stringdatetime)this.datetime=}publicStringgetAuthor()return}publicvoidsetAuthor(Stringauthor)this.author=}publicStringgetCid()return}publicvoidsetCid(Stringcid)this.cid=}publicStringgetExpress()return}publicvoidsetExpress(Stringexpress)this.express=}}publicclassHttpUtilspublicstaticfinalintMETHOD_GET=1;publicstaticfinalintMETHOD_POST=2;publicstaticHttpEntitygetEntity(Stringuri,List<NameValuePair>{HttpEntityentity=HttpClientclient=newHttpUriRequestrequest=null;caseMETHOD_GET//getStringBuildersb=new&&!params.isEmpty()){for(NameValuePairpair}}request=newcaseMETHOD_POST://post请求requestnewHttpPost(uri);&&!params.isEmpty()){UrlEncodedFormEntityreqEntity=new}}HttpResponseresponse=entity=}return}}6)MainActivityoncreateprivatestaticfinalStringip=TabHosthost=Stringuri=ip+":8080/androidServiceOfnews/GetAllCategory";HttpEntityentity=null;Stringinfo=tryentity=HttpUtils.getEntity(uri,null,info=}catch(Exception{}List<Category>clist=if(clist!=null)for(inti=0;i<clist.size();{Categoryc=(Category)TabSpectab=ent(newIntent(this,SszzActivity.class));}abSpectab=ent(newIntent(this,JsxwActivity.class));}abSpectab=ent(newIntent(this,TyxwActivity.class));}abSpectab=ent(newIntent(this,CjxwActivity.class));}abSpectab=ent(newIntent(this,ShzxActivity.class));}}}publicclassSszzActivityextendsprivateListViewprivateNewsAdapterprivatestaticfinalStringip="06";protectedvoidonCreate(BundleArrayList<News>newslist=//实例化lv=adapter=newNewsAdapter(this,}publicArrayList<News>List<NameValuePair>params=newArrayList<NameValuePair>();params.add(newBasicNameValuePair("cid","sszz"));HttpEntityentity=null;Stringinfo=tryentity=HttpUtils.getEntity(uri,params,HttpUtils.METHOD_GET);info=EntityUtils.toString(entity);}catch(Exception{}ArrayList<News>newslist=return}}publicclassJsonUtilpublicstaticArrayList<Category>parseJsonCategorylist(StringArrayList<Category>clist=newtryJSONArrayarray=newfor(inti=0;i<array.length();{JSONObjecttemp=(JSONObject)array.get(i);Categoryc=newCategory();intid=Stringcid=temp.getString("cid");Stringcname=temp.getString("cname");c=newCategory();}}catch(JSONException{System.out.println("Jsonparseerror");}return}publicstaticArrayList<News>parseJsonNewslist(StringArrayList<News>nlist=newtryJSONArrayarray=newfor(inti=0;i<array.length();{JSONObjecttemp=(JSONObject)array.get(i);Newsn=newNews();}}catch(JSONException{System.out.println("Jsonparseerror");}return}}publicclassNewsAdapterextendsprivateLayoutInflaterprivateArrayList<News>publicNewsAdapter(Contextcontext,ArrayList<News>nlist){inflater=LayoutInflater.from(context);this.newslist=this.newslist=new}}*publicintgetCount()//TODOAuto‐generatedmethodreturn}publicObjectgetItem(intposition)//TODOAuto‐generatedmethodreturn}publiclonggetItemId(intposition)//TODOAuto‐generatedmethodreturn}*返回指定位置数据绑定的itemconvertViewpublicViewgetView(intposition,ViewconvertView,ViewGroupparent){//TODOAuto‐generatedmethodstubViewHolderholder=newViewHolder();convertView=inflater.inflate(R.layout.item,null);holder=newViewHolder();holder.tvTitle=(TextView)holder.tvExpress=(TextView)holder.tvDatetime=(TextView)holder.tvA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 忻州师范学院《体育学科通识阅读与写作》2023-2024学年第二学期期末试卷
- 新疆维吾尔自治区阿克苏地区库车县乌尊镇中学2025年3月高三年级综合模拟测试生物试题含解析
- 江苏省淮安市淮安区达标名校2025届初三下学期期末教学质量检测试题试卷生物试题含解析
- 四川文化传媒职业学院《商务英语基础》2023-2024学年第一学期期末试卷
- 永州职业技术学院《汽轮机原理及设备》2023-2024学年第一学期期末试卷
- 山东省济南历下区重点名校2024-2025学年初三化学试题下学期一模预考试题含解析
- 厦门演艺职业学院《食品质量检测技术》2023-2024学年第二学期期末试卷
- 山东临清2025届初三数学试题模拟试卷(一)试题含解析
- 山西省运城市稷山县2025届初三下学期5月考试卷化学试题试卷含解析
- 威海职业学院《血液流变学与人体健康》2023-2024学年第一学期期末试卷
- 2025年中建阿尔及利亚公司招聘笔试参考题库含答案解析
- 无人机应聘面试简历
- 日立电梯LCA故障代码
- 2025年上海铁路局集团招聘笔试参考题库含答案解析
- 智能制造装备相关行业投资方案范本
- 山东省日照市莒县2020-2021学年高二下学期期中考试化学试题
- 2025中国铁路兰州局集团限公司招聘普通高校毕业生540人(二)管理单位笔试遴选500模拟题附带答案详解
- 谷草订购合同范例
- 《塑料基础知识培训》课件
- 煤质化验工职业技能竞赛理论考试题库500题(含答案)
- 老年患者围手术期多模式镇痛低阿片方案中国专家共识(2021全文版)
评论
0/150
提交评论