編輯:關於Android編程
package com.xiaowu.blogclient; import me.maxwin.view.IXListViewLoadMore; import me.maxwin.view.XListView; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Toast; import com.xiaowu.blogclient.adapter.BlogDetailAdapter; import com.xiaowu.blogclient.util.Constants; import com.xiaowu.blogclient.util.JsoupUtil; import com.xiaowu.blogclient.util.HttpUtil; /** * 博客詳細內容界面 * * @author wwj_748 * @date 2014/8/10 */ public class BlogDetailActivity extends Activity implements IXListViewLoadMore { private XListView listView; // 列表控件 private BlogDetailAdapter blogDetailAdapter; // 內容適配器 private ProgressBar progressBar; // 進度條 private ImageView reLoadImageView; // 重新加載的圖片 private ImageView backBtn; // 回退按鈕 private ImageView commentBtn; // 評論按鈕 public static String url; // 博客地址 private String filename; // 文件名字 @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE);// 無標題 super.onCreate(savedInstanceState); setContentView(R.layout.article_detail); init(); initComponent(); // 執行異步加載 new MainTask().execute(url, Constants.DEF_TASK_TYPE.FIRST); } // 初始化 private void init() { blogDetailAdapter = new BlogDetailAdapter(this); url = getIntent().getExtras().getString("blogLink"); filename = url.substring(url.lastIndexOf("/") + 1); System.out.println("filename--->" + filename); } // 初始化組件 private void initComponent() { progressBar = (ProgressBar) findViewById(R.id.blogContentPro); reLoadImageView = (ImageView) findViewById(R.id.reLoadImage); reLoadImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { reLoadImageView.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); } }); backBtn = (ImageView) findViewById(R.id.backBtn); backBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { finish(); } }); commentBtn = (ImageView) findViewById(R.id.comment); commentBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(); i.setClass(BlogDetailActivity.this, BlogCommentActivity.class); i.putExtra("filename", filename); startActivity(i); overridePendingTransition(R.anim.push_left_in, R.anim.push_no); } }); listView = (XListView) findViewById(R.id.listview); listView.setAdapter(blogDetailAdapter); listView.setPullLoadEnable(this); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) { // 獲取點擊列表項的狀態 int state = blogDetailAdapter.getList().get(position - 1) .getState(); switch (state) { case Constants.DEF_BLOG_ITEM_TYPE.IMG: // 點擊的是圖片 String url = blogDetailAdapter.getList().get(position - 1) .getImgLink(); Intent i = new Intent(); i.setClass(BlogDetailActivity.this, ImageActivity.class); i.putExtra("url", url); startActivity(i); break; default: break; } } }); } @Override public void finish() { super.finish(); } private class MainTask extends AsyncTask{ @Override protected Integer doInBackground(String... params) { // 通過http請求url地址,獲取html文檔 String temp = HttpUtil.httpGet(params[0]); if (temp == null) { if (params[1].equals(Constants.DEF_TASK_TYPE.FIRST)) { return Constants.DEF_RESULT_CODE.FIRST; } else { return Constants.DEF_RESULT_CODE.ERROR; } } // 添加解析出來的數據 blogDetailAdapter.addList(JsoupUtil.getContent(url, temp)); if (params[1].equals(Constants.DEF_TASK_TYPE.FIRST)) { return Constants.DEF_RESULT_CODE.REFRESH; } return Constants.DEF_RESULT_CODE.LOAD; } @Override protected void onPostExecute(Integer result) { if (result == Constants.DEF_RESULT_CODE.FIRST) { Toast.makeText(getApplicationContext(), "網絡信號不佳", Toast.LENGTH_LONG).show(); reLoadImageView.setVisibility(View.VISIBLE); } else if (result == Constants.DEF_RESULT_CODE.ERROR) { listView.stopLoadMore(); } else if (result == Constants.DEF_RESULT_CODE.REFRESH) { blogDetailAdapter.notifyDataSetChanged(); } else { blogDetailAdapter.notifyDataSetChanged(); listView.stopLoadMore(); } progressBar.setVisibility(View.INVISIBLE); super.onPostExecute(result); } } // 加載更多 @Override public void onLoadMore() { if (!JsoupUtil.contentLastPage) { new MainTask().execute(url, Constants.DEF_TASK_TYPE.NOR_FIRST); } else { // 在底部顯示“--THE END0--"文本 listView.stopLoadMore(" -- THE END --"); } } }
1.Volley結構圖從上圖可以看到Volley分為三個線程,分別是主線程、緩存調度線程、和網絡調度線程,首先請求會加入緩存隊列,如果發現可以找到相應的緩存結果就直接讀取
本文實例講述了android開發socket編程之udp發送實現方法。分享給大家供大家參考。具體分析如下:需要實現的功能:采用udp下的socket編程,當按下確認鍵,模
1.1 Gradle Build Files in Android1 settings.gradle位於根目錄,它指明了那些包含在多項目構建中的子項目(Android支持
android 異步任務的一個後台方法本質是開啟一個線程完成耗時操作,其他onPostExecute方法和onPreExecute方法運行在UI主線程用於更新UI界面。為