日期:2014-05-16 浏览次数:20382 次
package com.app.test02; import java.util.Map; import com.app.util.MyApplication; import android.app.Activity; import android.opengl.Visibility; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; public class HanderTest_Text extends Activity { private Button button; private TextView textView; private Handler handler; private ProgressBar progressBar; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_hander_text); button = (Button) findViewById(R.id.button1); textView = (TextView) findViewById(R.id.textView1); progressBar = (ProgressBar) findViewById(R.id.progressBar1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub progressBar.setVisibility(View.VISIBLE); button.setText("加载中..."); new MyThread().start(); } }); handler = new Handler(){ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); textView.setText(msg.obj.toString()); progressBar.setVisibility(View.GONE); button.setText("加载完成"); button.setEnabled(false); } }; } class MyThread extends Thread{ @Override public void run() { // TODO Auto-generated method stub String result = ApplicationDemo.handleGet("http://10.0.2.2:8888/android/"); Map map = ApplicationDemo.getMap(result); Message message = handler.obtainMessage(); message.obj = map.get("book"); try { sleep(30000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } handler.sendMessage(message); } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#fff" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加载文本" /> </LinearLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textColor="#000"/> </LinearL