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;  
            }  
        }  
    
    
  • 相关阅读:
    js事件
    增量
    文本文件输入(忽略行)
    当数据库的字段为date类型时候
    枚举的使用
    input输入框用el对数字格式化
    图片提交按钮各浏览器不兼容问题
    js对数字的校验
    时间控件
    ymPrompt消息提示组件4.0版 演示及使用简介
  • 原文地址:https://www.cnblogs.com/xiaoli3007/p/4432374.html
Copyright © 2011-2022 走看看