imageview 显示assets的图片

    package com.nobeg.adapter;  
    import java.io.InputStream;  
    /* 
     *  
     * 自定义主页面导航列表适配器 
     */  
    public class MainAdapter extends BaseAdapter {  
          
        private Context context;  
        private List<Map<String, Object>> rs=null;  
        AssetManager assetManager =null;  
        public MainAdapter(Context context,List<Map<String, Object>>  rs) {  
            // TODO Auto-generated constructor stub  
            this.context=context;  
            this.rs=rs;  
              
        }  
      
        public int getCount() {  
            // TODO Auto-generated method stub  
            return rs.size();  
        }  
      
        public Object getItem(int position) {  
            // TODO Auto-generated method stub  
            return position;  
        }  
      
        public long getItemId(int position) {  
            // TODO Auto-generated method stub  
            return 0;  
        }  
      
        public View getView(int position, View arg1, ViewGroup arg2) {  
            // TODO Auto-generated method stub  
            LayoutInflater flater = LayoutInflater.from(context);  
            /* 使用grid.xml为每几个item的Layout */  
            View v = (View) flater.inflate(R.layout.main_grid_item, null);  
            /* 取得View */  
            ImageView iv = (ImageView) v.findViewById(R.id.grid_img);  
            TextView tv = (TextView) v.findViewById(R.id.grid_text);  
            TextView moduleID = (TextView) v.findViewById(R.id.gongneng_flag);  
              
            /* 设置显示的文文字 */  
            tv.setText(rs.get(position).get("naviName").toString());  
            moduleID.setText(rs.get(position).get("moduleID").toString());  
            //这里才是重点  
            assetManager=context.getAssets();  
            try {  
                InputStream in=assetManager.open("img/main."+rs.get(position).get("moduleID").toString()+".png");  
                Bitmap bmp=BitmapFactory.decodeStream(in);  
                iv.setImageBitmap(bmp);  
            } catch (Exception e) {  
                // TODO: handle exception  
            }  
            return v;  
        }  
    }  

 

posted @ 2015-04-16 16:04  清风吹云  阅读(1233)  评论(0编辑  收藏  举报