实验5网络访问与服务Word格式.docx

上传人:b****1 文档编号:13167293 上传时间:2022-10-07 格式:DOCX 页数:8 大小:139.71KB
下载 相关 举报
实验5网络访问与服务Word格式.docx_第1页
第1页 / 共8页
实验5网络访问与服务Word格式.docx_第2页
第2页 / 共8页
实验5网络访问与服务Word格式.docx_第3页
第3页 / 共8页
实验5网络访问与服务Word格式.docx_第4页
第4页 / 共8页
实验5网络访问与服务Word格式.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

实验5网络访问与服务Word格式.docx

《实验5网络访问与服务Word格式.docx》由会员分享,可在线阅读,更多相关《实验5网络访问与服务Word格式.docx(8页珍藏版)》请在冰豆网上搜索。

实验5网络访问与服务Word格式.docx

1、创建项目

新建一个Android工程,目录结构如下图:

2、添加布局文件

修改main.xml布局文件,如下

<

?

xmlversion="

1.0"

encoding="

utf-8"

>

<

LinearLayoutxmlns:

android="

android:

orientation="

vertical"

layout_width="

fill_parent"

layout_height="

<

EditTextandroid:

wrap_content"

android:

id="

@+id/editText1"

text="

match_parent"

/>

LinearLayoutandroid:

android:

@+id/linearLayout3"

<

TextViewandroid:

@+id/textView2"

参数"

@+id/editText2"

source"

/LinearLayout>

@+id/linearLayout2"

@+id/textView1"

取值"

@+id/editText3"

2556800654"

@+id/linearLayout1"

Buttonandroid:

@+id/Button1"

android:

get"

@+id/Button2"

post"

<

ScrollViewxmlns:

scrollbars="

fadingEdge="

@+id/TextView01"

paddingTop="

5dip"

/>

/ScrollView>

3、创建Activity

publicclassslide8_3extendsActivity{

publicStringmyhttpget(Stringurl)throwsException{

Stringout=null;

try{

HttpClientclient=newDefaultHttpClient();

HttpGetrequest=newHttpGet(url);

HttpResponseresponse=client.execute(request);

out=EntityUtils.toString(response.getEntity());

}catch(IOExceptione){

e.printStackTrace();

}

returnout;

}

publicStringmyhttppost(Stringurl,Stringname,Stringvalue)

throwsException{

HttpPostrequest=newHttpPost(url);

List<

NameValuePair>

postParameters=newArrayList<

();

postParameters.add(newBasicNameValuePair(name,value));

UrlEncodedFormEntityformEntity=newUrlEncodedFormEntity(

postParameters);

request.setEntity(formEntity);

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

finalTextViewtextView=(TextView)findViewById(R.id.TextView01);

finalEditTexteditText=(EditText)findViewById(R.id.editText1);

finalEditTextname=(EditText)findViewById(R.id.editText2);

finalEditTextvalue=(EditText)findViewById(R.id.editText3);

Buttonbtn=(Button)this.findViewById(R.id.Button1);

btn.setOnClickListener(newButton.OnClickListener(){

publicvoidonClick(Viewv){

try{

textView.setText(myhttpget(editText.getText().toString()

+"

"

+name.getText().toString()+"

="

+value.getText().toString()));

}catch(Exceptione){

e.printStackTrace();

}

}

});

Buttonbtn2=(Button)this.findViewById(R.id.Button2);

btn2.setOnClickListener(newButton.OnClick

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 纺织轻工业

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1