I'm making my first App in Android Studio, but I'm having a hard time doing something relatively easy. I need a Click on a Button to show the TextView and another Button (which will hide the TextView when it is clicked again). But all the alternatives I researched and tried are locking the App. Would anyone have any similar code or would you have any suggestions?
After the help of @Skywalker the code is as follows, it is already working.
XML
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mostar_1"
android:id="@+id/btnMostar_1"
android:onClick= "clickBtnMostar_1"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mostar_2"
android:id="@+id/btnMostar_2"
android:onClick= "clickBtnMostar_2"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:id="@+id/LyMostar_1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Texto 1"
android:id="@+id/textMostar_1"
android:layout_below="@+id/LyMostar_1"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Esconder1"
android:id="@+id/btnEsconder1"
android:layout_below="@+id/btnMostar_1"
android:onClick= "clickBtnEsconder1"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:id="@+id/LyMostar_2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Texto 2"
android:id="@+id/textMostar_2"
android:layout_below="@+id/LyMostar_2"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Esconder2"
android:id="@+id/btnEsconder2"
android:layout_below="@+id/btnMostar_2"
android:onClick= "clickBtnEsconder2"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Java
public LinearLayout LyMostar_1;
public LinearLayout LyMostar_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela2);
LyMostar_1 = (LinearLayout) findViewById(R.id.LyMostar_1);
}
public void clickBtnMostar_1(View view) {
LyMostar_1.setVisibility(View.VISIBLE);
}
public void clickBtnEsconder1 (View esc){
LyMostar_1.setVisibility(View.INVISIBLE);
}
public void clickBtnMostar_2(View view) {
LyMostar_2.setVisibility(View.VISIBLE);
}
public void clickBtnEsconder2 (View esc){
LyMostar_2.setVisibility(View.INVISIBLE);
}
}