zoukankan      html  css  js  c++  java
  • 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;  
            }  
        }  
    
    
  • 相关阅读:
    文本标记
    第一个HTML文档
    HTML入门
    bootstrap fileinput 文件上传
    DPDK rte_hash 简述
    glib学习笔记-基本知识
    linux常用网络命令
    libevent学习过程
    C语言 singleton模式
    oracle命令行导出、导入dmp文件
  • 原文地址:https://www.cnblogs.com/xiaoli3007/p/4432374.html
Copyright © 2011-2022 走看看