zoukankan      html  css  js  c++  java
  • 权限---根据传递不用的值,显示不同的图标

    package com.example.textdemo2;
    
    import java.util.ArrayList;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
        private GridView mGridView;
        private ArrayList<SudokuCell> list = new ArrayList<MainActivity.SudokuCell>();
        private int ageData[] = new int[] { 0, 2, 7};
        
        // 九宫格显示的名字和对应的ID
        private class SudokuCell {
            public String name;
            public int rId;
        }
        
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            mGridView = (GridView) this.findViewById(R.id.gridView1);
            
            
            for (int i = 0; i < ageData.length; i++) { 
                SudokuCell sudokuCell = new SudokuCell();
                sudokuCell.rId = ageData[i]; 
                if (ageData[i] == 0) {
                    sudokuCell.rId = R.drawable.a0;
                    sudokuCell.name = "000";
                } else if (ageData[i] == 1) {
                    sudokuCell.rId = R.drawable.a1;
                    sudokuCell.name = "111";
                } else if (ageData[i] == 2) {
                    sudokuCell.rId = R.drawable.a2;
                    sudokuCell.name = "222";
                }else if (ageData[i] == 3) {
                    sudokuCell.rId = R.drawable.a3;
                    sudokuCell.name = "333";
                }else if (ageData[i] == 4) {
                    sudokuCell.rId = R.drawable.a4;
                    sudokuCell.name = "444";
                }else if (ageData[i] == 5) {
                    sudokuCell.rId = R.drawable.a5;
                    sudokuCell.name = "555";
                }else if (ageData[i] == 6) {
                    sudokuCell.rId = R.drawable.a6;
                    sudokuCell.name = "666";
                }else if (ageData[i] == 7) {
                    sudokuCell.rId = R.drawable.a7;
                    sudokuCell.name = "777";
                }
                list.add(sudokuCell);
            }
            
            mGridView.setAdapter(new MyAdapter());
            mGridView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    int resId = list.get(position).rId;
    
                    if (resId == R.drawable.a4) {
                        Toast.makeText(getBaseContext(), "444", 2).show();
                    } else if (resId == R.drawable.a0) {
                        Toast.makeText(getBaseContext(), "000", 2).show();
                    } else if (resId == R.drawable.a1) {
                        Toast.makeText(getBaseContext(), "111", 2).show();
                    } else if (resId == R.drawable.a2) {
                        Toast.makeText(getBaseContext(), "222", 2).show();
                    } else if (resId == R.drawable.a3) {
                        Toast.makeText(getBaseContext(), "333", 2).show();
                    } else if (resId == R.drawable.a5) {
                        Toast.makeText(getBaseContext(), "555", 2).show();
                    } else if (resId == R.drawable.a6) {
                        Toast.makeText(getBaseContext(), "666", 2).show();
                    } else if (resId == R.drawable.a7) {
                        Toast.makeText(getBaseContext(), "777", 2).show();
                    }
                }
            });
        }
        
        private class MyAdapter extends BaseAdapter {
    
            @Override
            public int getCount() {
                return list.size();
            }
    
            @Override
            public Object getItem(int position) {
                return list.get(position);
            }
    
            @Override
            public long getItemId(int position) {
                return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    convertView = LayoutInflater.from(MainActivity.this).inflate(
                            R.layout.fragment_mainpanel_item, null);
                }
                TextView txtName = (TextView) convertView
                        .findViewById(R.id.textView1);
                txtName.setCompoundDrawablesWithIntrinsicBounds(0,
                        list.get(position).rId, 0, 0);
    
                txtName.setText(list.get(position).name);
    
                return convertView;
            }
    
        }
    
     
    }
  • 相关阅读:
    论独立思考的重要性及策略
    linux的iptables和firewall的区别
    CentOS中防火墙相关的命令(CentOS7中演示)
    Capistrano:自动完成多台服务器上新版本的同步更新,包括数据库的改变
    CentOS7.0下安装FTP服务的方法
    nginx服务器究竟是怎么执行php项目
    centos7.0 可以访问HTML文件,不能访问PHP文件,因为php-fpm没有扩展包
    (二)Centos7下Yum更新安装PHP5.5,5.6,7.0
    centos7重启apache、nginx、mysql、php-fpm命令
    centOS 重启 php-fpm
  • 原文地址:https://www.cnblogs.com/androidsj/p/3236683.html
Copyright © 2011-2022 走看看