android - How to make views visible per button click -
i developing app calculation. consists of horizontal linearlayout
, each layout has 2 edit text , and spinner. want make in such way user can add layouts button click when needs add more details.
in xml set android:visibility="gone"
, in java set onclick
method make "gone" linear layout view.visible
. worked makes linear layouts appear once click + button. want them appear 1 after other (one appear , others remain "gone" until click button again)
you can use layout inflater.
create resource file in add layout , widgets required e.g item_resource.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <linearlayout android:id="@+id/linear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" /> <button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- other layout elements required --> </linearlayout>
then inflate above layout pragmatically on onclick event
layoutinflater inflater = (layoutinflater)context.getsystemservice (context.layout_inflater_service); view view = inflater .inflate(r.layout.item_resource,null); button button =(button)view.findviewbyid(r.id.btn); button.settext(" "); // set value
add view main layout e.g
linearlayout mylayout=(linearlayout)findviewbyid(r.id.xx); mylayout.add(view);
Comments
Post a Comment