【文件属性】:
文件名称:Android 单击选中的ImageButton[]图像数组用法示例.rar
文件大小:84KB
文件格式:RAR
更新时间:2022-07-30 06:38:34
Android源码-UI界面实例
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("");
}
【文件预览】:
codesc.net
----ImageButton()
--------.project(846B)
--------default.properties(449B)
--------AndroidManifest.xml(672B)
--------src()
--------res()
--------.classpath(280B)
--------gen()
--------assets()