如何从android中的代码(java)创建图像和链接按钮?

时间:2011-08-06 05:22:29

标签: java android android-layout android-widget

Android视图是在xml文件中,我们可以拖放n个控件到它,但是现在我想从java中的while循环创建图像和链接按钮,这意味着我们必须从后端开发接口部分,怎么能我们这样做了吗?

1 个答案:

答案 0 :(得分:1)

ImageButton inherits from ImageView and has its own properties compared to Button properties.

you can check properties here,
http://developer.android.com/reference/android/widget/ImageButton.html

Make your activity implement OnClickListener, then in OnCreate() or after that event. use ,

ImageButton btn = new ImageButton(this); or 
//ImageButton btn = (ImageButton) findViewById(R.id.imgbtnid)
btn.setOnClickListener(this);
in onClick() function you can handle the click event