Android学习笔记:图片访问数组

    //定义一个访问图片的数组

    int[] images = new int[] {

        R.drawable.java,

        R.drawable.ee,

        R.drawable.classic,

        R.drawable.ajax,

        R.drawable.xml,};


        这表明创建的图片数组有五个元素,图片来源于R.drawable资源中,后面的英文是图片名称,不是文件类型。


        

Android 单击选的ImageButton[]图像数组用法示例,类似于Radio的功能,不过用图片表现,这样可使Android UI更加友好,视觉更漂亮一些,用户轻触图片,即可选该数据项,比Radio用户体验更好,如截图所示的选效果,选后图像会变色:   setContentView(R.layout.main);   myTextView = (TextView) this.findViewById(R.id.myTextView);//得到myTextView的引用   imageButtons[0] = (ImageButton) this.findViewById(R.id.button01);//得到button01的引用   imageButtons[1] = (ImageButton) this.findViewById(R.id.button02);//得到button02的引用   imageButtons[2] = (ImageButton) this.findViewById(R.id.button03);//得到button03的引用   imageButtons[3] = (ImageButton) this.findViewById(R.id.button04);//得到button04的引用   for(ImageButton imageButton : imageButtons){   imageButton.setOnFocusChangeListener(this);//添加监听   我们同时使用了if else来判断各个ImageButton数组元素的选状态:   实现了接口的方法   if(v.getId() == R.id.button01){//改变的是button01时    myTextView.setText("您选了羊!");   }else if(v.getId() == R.id.button02){//改变的是button02时    myTextView.setText("您选了猪!");   }else if(v.getId() == R.id.button03){//改变的是button03时    myTextView.setText("您选了牛!");   }else if(v.getId() == R.id.button04){//改变的是button04时    myTextView.setText("您选了鼠!");   }else{//其他情况    myTextView.setText("");   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值