La casilla de verificación de Android marcada en una actividad y luego el botón aparece en otra actividad
La pregunta lo dice todo. Imagínese que hay 2 actividades, Actividad A y Actividad B. La Actividad A tiene una casilla de verificación cuando su botón marcado debe aparecer en la Actividad B cuando su casilla de verificación no esté marcada en "Actividad B"
Abajo está la actividad principal
- ¿Qué es sharedUserId en Android, y cómo se utiliza?
- ¿Cómo puedo borrar automáticamente el texto en EditText?
- Comprobar si la notificación de mi aplicación se está ejecutando
- Eclipse / Java - Valores en R.string. * Return int?
- Cómo enviar una matriz String como nombre de valor básico par como HTTPPOST?
public class MainActivity extends ActionBarActivity { private BubblesManager bubblesManager; private boolean isCheckedValue; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeBubblesManager(); final Button add = (Button) findViewById(R.id.add); add.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { addNewBubble(); add.setEnabled(false); } }); CheckBox checkBox = (CheckBox)findViewById(R.id.add_fb); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { isCheckedValue = isChecked; Intent intent = new Intent(MainActivity.this, PopUpWindow.class); intent.putExtra("yourBoolName", isCheckedValue ); } }); } private void addNewBubble() { BubbleLayout bubbleView = (BubbleLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.bubble_layout, null); bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() { @Override public void onBubbleRemoved(BubbleLayout bubble) { finish(); System.exit(0); } }); bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() { @Override public void onBubbleClick(BubbleLayout bubble) { Intent in = new Intent(MainActivity.this, PopUpWindow.class); startActivity(in); } }); bubbleView.setShouldStickToWall(true); bubblesManager.addBubble(bubbleView, 60, 20); }
A continuación se muestra la actividad siguiente aka 'actividad B'
public class PopUpWindow extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pop_up_window); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; getWindow().setLayout((int)(width*.8),(int)(height*.6)); Boolean yourBool = getIntent().getBooleanExtra("yourBoolName",false); Button fbbutton1 = (Button)findViewById(R.id.fbbutton1); if(yourBool){ //For Displaying Button fbbutton1.setVisibility(View.VISIBLE); } }
A continuación se muestra el código XML del botón que quiero mostrar cuando se hace clic en la casilla de verificación
<Button android:visibility="gone" android:id="@+id/fbbutton1" android:onClick="button" android:background="@drawable/fbcircle" android:layout_width="50dp" android:layout_height="50dp" />
- Escritorio remoto basado en web para conectarse a android
- Dalvik VM vs Sun JVM
- Cómo hacer HorizontalScrollView RIGHT a LEFT Scroll android
- Actividad con pestañas de Android Abajo de la pantalla
- Android: varios appWidgets que reproducen diferentes sonidos
- ContentResolver y la sentencia "IN" en la condición "where"
- ¿Cómo detectar el código de respuesta 404 de la excepción de IO?
- Final int parámetro utilizado en Runnable anónimo
public class MainActivity extends ActionBarActivity { private BubblesManager bubblesManager; private boolean isCheckedValue; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeBubblesManager(); final Button add = (Button) findViewById(R.id.add); add.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { addNewBubble(); add.setEnabled(false); } }); CheckBox checkBox = (CheckBox)findViewById(R.id.add_fb); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { isCheckedValue = isChecked; // un-comment this code if you want to go to second activity when check change // // Intent intent = new Intent(MainActivity.this, PopUpWindow.class); // intent.putExtra("yourBoolName", isCheckedValue ); // startActivity(intent); } }); } private void addNewBubble() { BubbleLayout bubbleView = (BubbleLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.bubble_layout, null); bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() { @Override public void onBubbleRemoved(BubbleLayout bubble) { finish(); System.exit(0); } }); bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() { @Override public void onBubbleClick(BubbleLayout bubble) { Intent in = new Intent(MainActivity.this, PopUpWindow.class); in.putExtra("yourBoolName", isCheckedValue ); startActivity(in); } }); bubbleView.setShouldStickToWall(true); bubblesManager.addBubble(bubbleView, 60, 20); } } public class PopUpWindow extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pop_up_window); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; getWindow().setLayout((int)(width*.8),(int)(height*.6)); Boolean yourBool = getIntent().getBooleanExtra("yourBoolName",false); Button fbbutton1 = (Button)findViewById(R.id.fbbutton1); if(yourBool){ //For Displaying Button fbbutton1.setVisibility(View.VISIBLE); } } }
Envíe un valor booleano con un paquete de intenciones en la actividad B. si es verdadero, muéstrelo u ocúltelo.
//global value private boolean isCheckedValue; CheckBox checkBox = (CheckBox)findViewById(R.id.chkbox1); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { isCheckedValue = isChecked; //first set value then assign to boolean extra. Intent intent = new Intent(MainActivity.this, PopUpWindow.class); intent.putExtra("yourBoolName", isCheckedValue ); startActivity(intent); } }); }
Enviar con intención
Intent intent = new Intent(this, AcitivityB.class); intent.putExtra("yourBoolName", isCheckedValue ); startActivity(intent)
Maneja eso en Acitivity B
Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName"); if(yourBool){ //display button } else{ //hide button }
Utilizar boolean isChecked de la "Actividad A" en ese estado de salvaguardia de la casilla de verificación, pasarlo a la "Actividad B", Utilizando esa visibilidad de conjunto booleana a su vista en "Actividad B".
Cambie su actividad 'A' de esta manera:
public class MainActivity extends ActionBarActivity { private BubblesManager bubblesManager; private boolean isCheckedValue; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeBubblesManager(); final Button add = (Button) findViewById(R.id.add); add.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { addNewBubble(); add.setEnabled(false); } }); intent = new Intent(MainActivity.this, PopUpWindow.class); CheckBox checkBox = (CheckBox)findViewById(R.id.add_fb); checkBox.setOnCheckedChangeListener (newCompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { isCheckedValue = isChecked; intent.putExtra("yourBoolName", isCheckedValue ); } }); } private void addNewBubble() { BubbleLayout bubbleView = (BubbleLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.bubble_layout, null); bubbleView.setOnBubbleRemoveListener(new BubbleLayout.OnBubbleRemoveListener() { @Override public void onBubbleRemoved(BubbleLayout bubble) { finish(); System.exit(0); } }); bubbleView.setOnBubbleClickListener(new BubbleLayout.OnBubbleClickListener() { @Override public void onBubbleClick(BubbleLayout bubble) { startActivity(intent); } }); bubbleView.setShouldStickToWall(true); bubblesManager.addBubble(bubbleView, 60, 20); }
Y obtendrá un valor agregado adicional en la Actividad 'B'
boolean checkedStatus= getIntent().getBooleanExtra("yourBoolName",false); if(checkedStatus){ // Do your job here }else{ }
- Android Clic en el texto de la pantalla
- ClassCastException: CustomFragment no se puede convertir en android.app.Fragment / Using android.support.v4.app.Fragment