【问题标题】:How can i create image and link button from code (java) in android?如何从 android 中的代码 (java) 创建图像和链接按钮?
【发布时间】:2011-08-06 05:22:28
【问题描述】:

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

【问题讨论】:

  • 很好。你能解释一下你做了什么吗:)

标签: java android android-layout android-widget


【解决方案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

【讨论】:

    猜你喜欢
    • 2011-11-25
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多