編輯:關於Android編程
package com.example.thread; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import com.example.test.R; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Toast; public class AsyncTaskActivity extends Activity{ private ImageView mImageView; private Button mButton; private ProgressBar mProgressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main12); mImageView = (ImageView)findViewById(R.id.imageView); mButton = (Button)findViewById(R.id.button); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new MyAsyncTask().execute("http://csdnimg.cn/www/images/csdnindex_logo.gif"); } }); } class MyAsyncTask extends AsyncTask<String, Integer, Bitmap>{ @Override protected Bitmap doInBackground(String... params) { publishProgress(0);//將會調用onProgressUpdate(Integer... progress)方法 HttpClient hc = new DefaultHttpClient(); publishProgress(30); HttpGet hg = new HttpGet(params[0]); final Bitmap bm; try { HttpResponse hr = hc.execute(hg); bm = BitmapFactory.decodeStream(hr.getEntity().getContent()); } catch (Exception e) { return null; } publishProgress(100); return bm; } @Override protected void onProgressUpdate(Integer... values) { mProgressBar.setProgress(values[0]); } @Override protected void onPostExecute(Bitmap result) { if (result != null) { Toast.makeText(AsyncTaskActivity.this, "成功獲取圖片", Toast.LENGTH_LONG).show(); mImageView.setImageBitmap(result); }else { Toast.makeText(AsyncTaskActivity.this, "獲取圖片失敗", Toast.LENGTH_LONG).show(); } } @Override protected void onPreExecute() { mImageView.setImageBitmap(null); mProgressBar.setProgress(0); super.onPreExecute(); } @Override protected void onCancelled() { super.onCancelled(); mProgressBar.setProgress(0); } } }
1.import android.app.Activity;import android.content.Context;import android.content.r
調用系統自帶的文件浏覽器這很簡單:/** 調用文件選擇軟件來選擇文件 **/ private void showFileChooser() { intent = ne
緒論最近項目裡面用到了下拉刷新和左滑刪除,網上找了找並沒有可以用的,有比較好的左滑刪除,但是並沒有和下拉刷新上拉加載結合到一起,要不就是一些比較水的結合,並不能在項目裡面
打印機其實和Android沒有什麼大的關系,和linux內核關聯才是比較強的。最近調試打印機,有那麼一點心得,一點一點記錄下來。 最終的結果是要在Andro