Question

I have a layout that I'm modifying with only one class.

<LinearLayout 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="#FFCCCCCC"
android:orientation="vertical"
android:id="@+id/activity_main"
tools:context=".MainActivity" >

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

   <ImageButton
        android:id="@+id/nuevo_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/nuevo"
        android:src="@drawable/nueva" />

    <ImageButton
        android:id="@+id/resistencia_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/resistencia"
        android:src="@drawable/resistencia" />

    <ImageButton
        android:id="@+id/condensador_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/condensador"
        android:src="@drawable/condensador" />

    <ImageButton
        android:id="@+id/pila_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/pila"           
        android:src="@drawable/pila" />

    <ImageButton
        android:id="@+id/tierra_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/tierra"            
        android:src="@drawable/tierra" />

    <ImageButton
        android:id="@+id/cable_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/cable"            
        android:src="@drawable/cable" />

</LinearLayout>

 <HorizontalScrollView
  android:id="@+id/scrollVieW"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/linearlayoutUp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >


</LinearLayout>
</HorizontalScrollView>  
<com.example.nuevo.ControladorView
    android:id="@+id/drawing"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_marginBottom="3dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="3dp"
    android:layout_weight="0.92" />

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

    <ImageButton
        android:id="@+id/play_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/play"
        android:src="@drawable/play" />


    <ImageButton
        android:id="@+id/papelera_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/papelera"
        android:src="@drawable/papelera" />

    <ImageButton
        android:id="@+id/rotate_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/rotar"
        android:src="@drawable/rotate" />


</LinearLayout>


 <HorizontalScrollView
  android:id="@+id/scrollVieWDown"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/linearlayoutDown"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

   <ImageButton
        android:id="@+id/stop_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/stop"
        android:src="@drawable/stop" />

   <ImageButton
        android:id="@+id/verNodos_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/verNodos"
        android:src="@drawable/ver_nodos" />

  <ImageButton
        android:id="@+id/autoresolver_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/autoresolver"
        android:src="@drawable/autoresolver" />

  <ImageButton
        android:id="@+id/ecuaciones_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/ecuaciones"
        android:src="@drawable/ecuaciones" />


</LinearLayout>

To modify this view I've used:

if(v.getId()==R.id.stop_btn){




         LinearLayout a = (LinearLayout)findViewById(R.id.elementoslayout);
         a.setVisibility(View.VISIBLE);


         LinearLayout buttonsLayout = (LinearLayout)findViewById(R.id.linearlayoutUp);
         buttonsLayout.setVisibility(View.GONE);



         LinearLayout herramientaslayout = (LinearLayout)findViewById(R.id.herramientaslayout);
         herramientaslayout.setVisibility(View.VISIBLE);


         LinearLayout mallaslayout = (LinearLayout)findViewById(R.id.linearlayoutDown);
         mallaslayout.setVisibility(View.GONE);



    }

When I click one button of this layout it appears a new layout. I want to return to the first layout in the same state before click the button. I try to do this but it appears the layout without the last updates.

Button buttonBack= (Button) findViewById(R.id.ButtonBack);
         buttonBack.setText("back");
        buttonBack.setOnClickListener(new OnClickListener() {
               public void onClick(View v) {
                   Intent ic1 = new Intent(getBaseContext(), Controlador.class);
                   finish();
                  startActivity(ic1);

               }
         });

No correct solution

OTHER TIPS

Don't finish the first activity. When finishing the second one you will return to the first in its last state.

Dont call

startActivity(ic1);

from second activity. Just call finish()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top