Reputation: 777
I have a main layout and in this layout I use a button on android application, when user click on this button show a second layout(with include tag). How can I call activity(I mean activity for second layout)? On second layout,I use a button, I want to set event for this button. How to do that?
Upvotes: 2
Views: 2795
Reputation: 777
my main xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark">
<include
android:id="@+id/include1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/second"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button"/>
second.xml file:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#13352E" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="18dp"
android:text="Close" />
</LinearLayout>
and this my mainactivity:
Button btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LinearLayout le=(LinearLayout)findViewById(R.id.linearLayout1);
le.setVisibility(View.VISIBLE);
}
});
}
and also this my secondactivity:
Button btn=(Button) findViewById(R.id.button2);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LinearLayout le=(LinearLayout)findViewById(R.id.linearLayout1);
le.setVisibility(View.INVISIBLE);
}
});
on second activity,button on click not work
Upvotes: 1
Reputation: 352
you are making yourself confused. you just need to add android:visibility="hidden" for the layout which you are treating as second xml. then on Onclick of button change the visibility of this layout;
Upvotes: 0