編輯:關於Android編程
數據格式為
{sid:737, tts:http://news.iciba.com/admin/tts/2013-12-11.mp3, content:I don't want us to be together because we have to,I want us to be together because we want to., note:我不希望我們因為“不得不”而在一起,我希望我們是因為想在一起而在一起。, translation:感謝@程很多要秒虐數學 投稿。詞霸小編,這句話來自《冰河世紀2》,是一個系列的動畫電影,非常搞笑,你看過嗎?, picture:http://cdn.iciba.com/news/word/2013-12-11.jpg,picture2:http://cdn.iciba.com/news/word/big_2013-12-11b.jpg,caption:詞霸每日一句, dateline:2013-12-11, s_pv:8693, sp_pv:2090, tags:[{id:9,name:愛情},{id:14,name:電影經典}], fenxiang_img:http://cdn.iciba.com/web/news/longweibo/imag/2013-12-11.jpg}
JSON字段解釋
JSON 字段解釋 { 'sid':'' #每日一句ID 'tts': '' #音頻地址 'content':'' #英文內容 'note': '' #中文內容 'translation':'' #詞霸小編 'picture': '' #圖片地址 'picture2': '' #大圖片地址 'caption':'' #標題 'dateline':'' #時間 's_pv':'' #浏覽數 'sp_pv':'' #語音評測浏覽數 'tags':'' #相關標簽 'fenxiang_img':'' #合成圖片,建議分享微博用的 }
最終實現的效果
具體實現,使用AsynTask異步訪問網絡:
class Load extends AsyncTask{ public String url = http://open.iciba.com/dsapi/; ProgressDialog pdlg; String jsonstr = ; JSONObject json = null; @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub try{ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httppost); HttpEntity httpEntity = httpResponse.getEntity(); InputStream is = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF-8)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + ); } is.close(); jsonstr = sb.toString(); json = new JSONObject(jsonstr.toString()); engstr = json.getString(content); chistr = json.getString(note); imagurl = json.getString(picture); timestr = json.getString(dateline); fromstr = json.getString(translation); JSONArray array = json.getJSONArray(tags); for(int i=0;i 使用了一個圖片處理的工具類,ImageLoader,主要用來通過url解析圖片,處理圖片的大小,以文件的形式緩存圖片。
public class ImageLoader { MemoryCache memoryCache=new MemoryCache(); FileCache fileCache; private MapimageViews=Collections.synchronizedMap(new WeakHashMap ()); ExecutorService executorService; public ImageLoader(Context context){ fileCache=new FileCache(context); executorService=Executors.newFixedThreadPool(5); } final int stub_id = R.drawable.drug_trans; public void DisplayImage(String url, ImageView imageView) { imageViews.put(imageView, url); Bitmap bitmap=memoryCache.get(url); if(bitmap!=null) imageView.setImageBitmap(bitmap); else { queuePhoto(url, imageView); imageView.setImageResource(stub_id); } } private void queuePhoto(String url, ImageView imageView) { PhotoToLoad p=new PhotoToLoad(url, imageView); executorService.submit(new PhotosLoader(p)); } private Bitmap getBitmap(String url) { File f=fileCache.getFile(url); //from SD cache Bitmap b = decodeFile(f); if(b!=null) return b; //from web try { Bitmap bitmap=null; URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setInstanceFollowRedirects(true); InputStream is=conn.getInputStream(); OutputStream os = new FileOutputStream(f); Utils.CopyStream(is, os); os.close(); bitmap = decodeFile(f); return bitmap; } catch (Exception ex){ ex.printStackTrace(); return null; } } //decodes image and scales it to reduce memory consumption private Bitmap decodeFile(File f){ try { //decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //Find the correct scale value. It should be the power of 2. final int REQUIRED_SIZE=70; int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; while(true){ if(width_tmp/1.5
1.這篇博文不算什麼知識點。使用的都是的系統中已經提供給我們的方式方法。這是最近用到了,感覺很實用,特此貢獻出來。 首先需要定義,listview中需要展示的
轉載請注明來源http://blog.csdn.net/siyehuazhilian/article/details/41803059 Android Studio快捷
第十八章、代理模式 代理模式也稱委托模式,是結構型設計模式之一。是應用廣泛的模式之一。1.定義為其他對象提供一種代理以控制對這個對象的訪問。2.使用場景當無法或不想直接訪
hello,大家好,本文主要介紹如何開始開發一個美觀、有情調、人見人愛的Android應用程序,已知我們在市面上有不少布局極其精美,在視覺上讓人愛不釋手的應用程序,如果讓