java - How to create custom button onClick() event Android(Studio)? -


i'm creating first android app, , part of it, need add new buttons after click on button.

then need create() button after onclick() event on button.

how it? things should know:

  • i using android studio develop app,
  • i have imported these:

    import android.view.*; import android.widget.button; import android.widget.textview; 
  • and i'd know whole library list android, or better, i'd what's best android library develop on such these things, need find , experienced on library i'll need suggestions!

thanks lot in advance :)

p.s. typed create() , onclick() make clear talking methods, not both of 'em real ones or ones i'll need ;)

p.p.s. don't know how many buttons ther becuase not choose that, user does, it's somethig like: want create new thing, press button '+' , create new button (the new thing), reason, amount of buttons isn't known, that's why can't use visibility trick, yeah first thought aswell!

rockfight's answer correct, recommend use button in layout android:visibility="gone" , show when user taps on first button using button2.setvisibility(view.visible). it's easier create layouts , views in xml instead of code. personally, i'm using support-v4 library, recyclerview, recently-released design library , of google play services libraries.

edit: if you're going add lot of buttons, , don't know how many, i'd recommend use listview or recyclerview. prefer recyclerview, might more difficult set up. anyway, you'll adding items list. items buttons, item layout this:

item_layout.xml  <?xml version="1.0" encoding="utf-8"?> <button xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="this new button!"     android:layout_margin="16dp"     android:gravity="center_vertical|center_horizontal"     android:elevation="2dp"     android:translationz="6dp" />     <!-- material design. see http://www.google.com/design/spec/what-is-material/elevation-shadows.html#elevation-shadows-elevation-android- -->     <!-- attributes need...... --> 

that's all. don't have mess ugly code. if want idea of advantages of recyclerview, see http://antonioleiva.com/recyclerview/.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -