編輯:關於android開發
public class MainActivity extends Activity { private TextView show; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); show=(TextView)findViewById(R.id.show); show.setMovementMethod(ScrollingMovementMethod.getInstance()); btn=(Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub doTask(); } }); } private void doTask() { // TODO Auto-generated method stub DownTask task=new DownTask(this,show); try { task.execute(new URL("http://www.szit.edu.cn/")); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
2.2 AsyncTask的子類DownTask代碼
public class DownTask extends AsyncTask<URL, Integer, String> { ProgressDialog progressDialog; int hasRead=0; Context context; TextView show; public DownTask(Context context,TextView show) { this.context=context; this.show=show; } @Override protected String doInBackground(URL... arg0) { // TODO Auto-generated method stub StringBuilder sb=new StringBuilder(); try { URLConnection conn=arg0[0].openConnection(); BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream(),"gb2312")); String line=""; while ((line=br.readLine())!=null) { sb.append(line+"\n"); hasRead++; publishProgress(hasRead); } } catch (Exception e) { // TODO: handle exception } return sb.toString(); } @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub show.setText(result); progressDialog.dismiss(); } @Override protected void onPreExecute() { // TODO Auto-generated method stub progressDialog=new ProgressDialog(context); progressDialog.setTitle("任務執行中"); progressDialog.setMessage("敬請等待"); progressDialog.setCancelable(false); progressDialog.setMax(300); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setIndeterminate(false); progressDialog.show(); } @Override protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub show.setText("已讀取"+values[0]+"行"); progressDialog.setProgress(values[0]); } }
AsyncTask的其他使用實例,可以進一步參考Android 多線程-----AsyncTask詳解(http://www.cnblogs.com/xiaoluo501395377/p/3430542.html)。
新浪微博登錄界面上下拉伸圖片--第三方開源--PullToZoomListViewEx(二),新浪微博第三方登錄 這是PullZoomView在Scroll
安卓客戶端a標簽長按彈框提示解決辦法,安卓標簽昨天工作時候發現一個bug,是關於a標簽的,在安卓客戶端中,如果是a標簽的話,長按會出現一個彈框,如圖所示 是因為安卓客戶端
二維碼的掃描和生成--第三方開源--ZXing,--第三方開源--zxingZXing的二維碼功能的提取lib下載地址:https://github.com/xuyish
Android用路徑api在內部存儲讀寫文件,androidapi復制並修改原有項目 復制之前創建的項目CC+CV操作 需要改動的地方: * 項目名字 * 應用包名 *