-1

How can I add view (with linear layout id/linearlayout_tambahkeluhan can add automatically when I click button id/tambah_keluhan) in case that...the content in linearlayout_tambahkeluhan is id/layout_keluhan, id/layout_status, id/layout_tindakan...How the code in Java? anyone can help me? Thx before

<LinearLayout
                    android:id="@+id/linearlayout_tambahkeluhan"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/layout_keluhan" >

                        <TextView
                            android:id="@+id/textView11"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:text="KELUHAN"
                            android:textColor="@color/blue" />

                        <TextView
                            android:id="@+id/textView12"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="0.5"
                            android:text=":"
                            android:textColor="@color/blue" />

                        <Spinner
                            android:id="@+id/spinner_keluhan"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="4" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/layout_status" >

                        <TextView
                            android:id="@+id/textView13"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:text="STATUS"
                            android:textColor="@color/blue" />

                        <TextView
                            android:id="@+id/textView14"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="0.5"
                            android:text=":"
                            android:textColor="@color/blue" />

                        <Spinner
                            android:id="@+id/spinner_status"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="4" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/layout_tindakan" >

                        <TextView
                            android:id="@+id/textView15"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:text="TINDAKAN"
                            android:textColor="@color/blue" />

                        <TextView
                            android:id="@+id/textView16"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="0.5"
                            android:text=":"
                            android:textColor="@color/blue" />

                        <EditText
                            android:id="@+id/editText_tindakan"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:ems="10"
                            android:textColor="@color/black" />
                    </LinearLayout>

                </LinearLayout>

                <Button
                    android:id="@+id/button_tambahkeluhan"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:background="@android:color/transparent"
                    android:onClick="onClick"
                    android:text="tambah keluhan"
                    android:textColor="@color/blue"
                    android:textStyle="italic" />
Anonymous
  • 37
  • 3

2 Answers2

0

You try addView(View view) function) with view can be controls or xml layout. Example: ((LinearLayout)findViewById(R.id.linearlayout_tambahkeluhan)).addView(btnNew);

Nam Hoang
  • 46
  • 3
  • What view you want to add when you click button? addView(View view) work ok with me. I don't understand you purpose? – Nam Hoang May 13 '15 at 04:47
0

Add to your linearLayout visibility 'gone' like this:

             <LinearLayout
                android:id="@+id/linearlayout_tambahkeluhan"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" 
                android:visibility="gone">

Then in onCreate function in your Activity do this:

LinearLayout yourLinearLayout=(LinearLayout)findViewById(R.id.linearlayout_tambahkeluhan);    
Button yourButton = (Button)findViewById(R.id.button_tambahkeluhan);
yourButton.setOnClickListener(new OnClickListener() {           
@Override
public void onClick(View v) {
    yourLinearLayout.setVisibility(View.Visible);
}
}
belen
  • 183
  • 2
  • 19
  • it can't works but i want to add more the layout..not to show/hide the layout? can you help me to think the code? thx – Anonymous May 13 '15 at 04:07