How is the nested layout visible when the root layout is clicked?
I am developing an Android application in that I have a linear layout that contains one root layout (prompt_single) and two nested layouts, namely (hidden, hidden1). In the layout "hidden1" I have two text images and the "hidden" layout contains three buttons (yes, no, maybe), now my need is when I need to click the root of the layout, I need to see two nested layouts in one and then same time, after visible layout, when I click any of these buttons (yes, no, maybe) the nested layout is hidden and the appearance of the root layout is shown again. here is my layout code,
<ImageButton
android:id="@+id/image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_action_event" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="true"
android:orientation="vertical">
<TextView
android:id="@+id/invitation_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:paddingTop="3dp"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/invitation_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:textColor="@color/black"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/hidden1"
android:layout_width="1000dp"
android:layout_height="50dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="true"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:paddingLeft="0dp"
android:paddingRight="10dp"
android:paddingTop="3dp"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:paddingLeft="0dp"
android:paddingRight="10dp"
android:textColor="@color/black"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/hidden"
android:layout_width="310dp"
android:layout_height="60dp"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingTop="1dp"
android:visibility="gone"
android:weightSum="3">
<Button
android:id="@+id/yesbutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="7dp"
android:layout_weight="1"
android:background="@color/blue"
android:text="Yes"
android:textColor="@color/black"></Button>
<Button
android:id="@+id/nobutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:background="@color/blue"
android:text="No"
android:textColor="@color/black"></Button>
<Button
android:id="@+id/buttonmaybe"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:background="@color/blue"
android:text="Maybe"
android:textColor="@color/black"></Button>
</LinearLayout>
</LinearLayout>
In the code below, the layout is the root layout first and the second and third layout are nested layouts, while coding I am trying to see the nested layouts when the root layout is clicked, but the nested layout "hidden" is only available, but I need to see both visible subpatterns at the same time when i click layout, hidden nested layouts need to go away and show root layout. How can I achieve this ...
final LinearLayout first = (LinearLayout)convertView.findViewById(R.id.invitation_single);
final LinearLayout second =
(LinearLayout) convertView.findViewById(R.id.hidden);
final LinearLayout third =
(LinearLayout) convertView.findViewById(R.id.hidden1);
first.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
second.setVisibility(View.VISIBLE);
third.setVisibility(View.VISIBLE);
}
});
source to share
Try this way,
final LinearLayout rootLayout= (LinearLayout)convertView.findViewById(R.id.invitation_single);
rootLayout.setOnClickListener(this);
// Then add onClickListener method and do what you want.
@Override
public void onClick(View v) {
//do what you want to do when button is clicked
switch (v.getId()) {
case R.id.invitation_single:
// Do your staff
break;
}
}
source to share
first of all you need to set visibility in both of your child layouts.
final LinearLayout rootLayout= (LinearLayout)convertView.findViewById(R.id.invitation_single);
final LinearLayout ChildLayout1= (LinearLayout)convertView.findViewById(R.id.ChildLayout1);
final LinearLayout ChildLayout2= (LinearLayout)convertView.findViewById(R.id.ChildLayout2);
rootLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//set visibility for your child layout
ChildLayout1.setVisibility(View.Visible);
ChildLayout2.setVisibility(View.Visible);
}
});
source to share