第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我自己寫(xiě)了一個(gè)用listview加載本地內(nèi)存卡的圖片,預(yù)期效果是顯示所有的本地內(nèi)存卡的圖片,而結(jié)果卻是在listview中顯示幾張圖片,下面是我寫(xiě)的代碼,求指教

我自己寫(xiě)了一個(gè)用listview加載本地內(nèi)存卡的圖片,預(yù)期效果是顯示所有的本地內(nèi)存卡的圖片,而結(jié)果卻是在listview中顯示幾張圖片,下面是我寫(xiě)的代碼,求指教

ArryLuo 2015-12-19 10:19:29
public?class?MainActivity?extends?Activity?{ private?ImageView?imageView; private?ListView?listView; List<Bitmap>?list?=?GetBitmap.getbitmap(); @Override protected?void?onCreate(Bundle?savedInstanceState)?{ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView?=?(ListView)?findViewById(R.id.listview); new?Myasynctak().execute("mnt/sdcard"); } class?Myasynctak?extends?AsyncTask<String,?Void,?List<ImgBen>>?{ @Override protected?List<ImgBen>?doInBackground(String...?params)?{ //?TODO?Auto-generated?method?stub return?getUrl(params[0]); } @Override protected?void?onPostExecute(List<ImgBen>?result)?{ //?TODO?Auto-generated?method?stub super.onPostExecute(result); MyAdpter?adpter=new?MyAdpter(MainActivity.this,?result); listView.setAdapter(adpter); } } private?List<ImgBen>?getUrl(String?url)?{ List<ImgBen>?list?=?new?ArrayList<ImgBen>(); File?file?=?new?File(url); //?判斷是否是文件 if?(file.exists())?{ File[]?arry?=?file.listFiles(); for?(int?i?=?0;?i?<?arry.length;?i++)?{ String?name?=?arry[i].getName();//?獲取這個(gè)文件的名稱(chēng) if?(name.endsWith(".jpg")?||?name.endsWith(".png"))?{ //?獲取他的絕對(duì)路徑 String?filepath?=?arry[i].getAbsolutePath(); ImgBen?ben?=?new?ImgBen(filepath); list.add(ben); } } } return?list; } }//這個(gè)Javabeanpublic class ImgBen {private String url;public ImgBen() { super(); // TODO Auto-generated constructor stub}public ImgBen(String url) { super(); this.url = url;}public String getUrl() { return url;}public void setUrl(String url) { this.url = url;}}//這個(gè)是加載圖片的異步操作public class LoginThread { ImageView mimageView; Handler mhandler=new Handler(){ public void handleMessage(android.os.Message msg) { mimageView.setImageBitmap((Bitmap) msg.obj); }; }; public void showThread(ImageView imageView, final String url) { mimageView=imageView; new Thread(){ @Override public void run() { // TODO Auto-generated method stub super.run(); Bitmap bitmap=getbitmapImage(url); Message message=new Message(); message.obj=bitmap; mhandler.sendMessage(message); } }.start(); } public Bitmap getbitmapImage(String url){ Bitmap bitmap=null; FileInputStream fis=null; BufferedInputStream bis=null; try { fis=new FileInputStream(url); bis=new BufferedInputStream(fis); bitmap=BitmapFactory.decodeStream(bis); return bitmap; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try { bis.close(); fis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }}//這個(gè)是我適配器public class MyAdpter extends BaseAdapter { private LayoutInflater inflater; private List<ImgBen>list; public MyAdpter(Context context,List<ImgBen>list) { inflater = LayoutInflater.from(context); this.list=list; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.item, null); ImgBen bitmap=list.get(position); ImageView imageView= (ImageView) view.findViewById(R.id.image); new LoginThread().showThread(imageView, bitmap.getUrl()); return view; }}
查看完整描述

2 回答

已采納
?
Hello橙子

TA貢獻(xiàn)13條經(jīng)驗(yàn) 獲得超0個(gè)贊

你看看你在獲取所有圖片路徑的時(shí)候是不是遍歷了根目錄所有的文件夾和子文件夾。getUrl(String?url)就是這個(gè)方法。

查看完整回答
反對(duì) 回復(fù) 2015-12-20
?
ArryLuo

TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超2個(gè)贊

在MainActivity中的List<Bitmap>?list?=?GetBitmap.getbitmap();是沒(méi)用的,剛剛提交的時(shí)候忘了把他注釋掉

查看完整回答
反對(duì) 回復(fù) 2015-12-19
  • 2 回答
  • 0 關(guān)注
  • 1697 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)