直奔主题~!

结构如图:

第七篇 ScrollView控件

main.xml代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayout android:layout_width="fill_parent"android:id="@+id/linearLayout1" android:layout_height="wrap_content"><EditText android:id="@+id/address_txt" android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_weight="1"><requestFocus></requestFocus></EditText><Button android:text="submti" android:id="@+id/submit_btn"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout><ScrollView android:layout_width="fill_parent"android:layout_height="wrap_content" android:id="@+id/scrollView1"><LinearLayout android:id="@+id/linearLayout2"android:layout_width="fill_parent" android:layout_height="fill_parent"><TextView  android:id="@+id/result"android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>        </LinearLayout></ScrollView></LinearLayout>

Control_ScrollViewActivity.java代码:

public class Control_ScrollViewActivity extends Activity {private EditText httpaddress;private Button submit_btn;private TextView result_txt;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);findAll();bind();}public void findAll() {httpaddress = (EditText) this.findViewById(R.id.address_txt);submit_btn = (Button) this.findViewById(R.id.submit_btn);result_txt = (TextView) this.findViewById(R.id.result);}public void bind() {submit_btn.setOnClickListener(mylistener);}private View.OnClickListener mylistener = new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubmyTast mt = new myTast(Control_ScrollViewActivity.this);mt.execute(httpaddress.getText().toString().trim());}};class myTast extends AsyncTask<String, Integer, String> {@Overrideprotected void onCancelled() {// TODO Auto-generated method stubsuper.onCancelled();}@Overrideprotected void onPostExecute(String result) {// TODO Auto-generated method stub// super.onPostExecute(result);result_txt.setText(result);pd.dismiss();}@Overrideprotected void onPreExecute() {// TODO Auto-generated method stub// super.onPreExecute();result_txt.setText("正在获取信息......");}@Overrideprotected void onProgressUpdate(Integer... values) {// TODO Auto-generated method stub// super.onProgressUpdate(values);pd.setProgress(values[0]);}ProgressDialog pd;public myTast(Context ct) {pd = new ProgressDialog(ct);pd.setCancelable(true);pd.setMax(100);pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);pd.setButton("cancel", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubdialog.cancel();}});pd.setOnCancelListener(new DialogInterface.OnCancelListener() {public void onCancel(DialogInterface dialog) {// TODO Auto-generated method stubfinish();}});pd.show();}@Overrideprotected String doInBackground(String... arg0) {// TODO Auto-generated method stub// return null;try {HttpClient client = new DefaultHttpClient();HttpGet get = new HttpGet(arg0[0]);HttpResponse response = client.execute(get);HttpEntity entity = response.getEntity();long length = entity.getContentLength();InputStream is = entity.getContent();String s = null;if (is != null) {ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] buf = new byte[128];int ch = -1;int count = 0;while ((ch = is.read(buf)) != -1) {baos.write(buf, 0, ch);count += ch;if (length > 0) {        publishProgress((int) ((count / (float) length) * 100));}  Thread.sleep(10);}s = new String(baos.toByteArray());}  return s;} catch (Exception e) {e.printStackTrace();}return null;}}}

更多相关文章

  1. Android改变图片颜色的自定义控件(十)
  2. android控件 ToggleButton的应用
  3. [置顶] android studio 如何进行格式化代码 快捷键必备
  4. android纯Java代码写的addView弹窗(亲测可用,欢迎留言)
  5. 整理的Android多种控件步骤
  6. 第四篇 Gallery控件
  7. android 代码设置apn

随机推荐

  1. PowerDesigner 生成SQL Server 2005 注释
  2. 使用sqoop从mysql往hive中增量导数据shel
  3. 使用VS 2012调试PostgrelSQL
  4. 让我的MySQL能够承受上亿万条的数据量的
  5. MySQL数据库的基本操作
  6. sql System.Data.SqlClient.SqlError: 无
  7. webgote的例子(6)SQL注入(盲注)
  8. c访问mysql总报错,请指教
  9. MySQL图形界面客户端
  10. [sql2008错误问题] RegisteredServerExce