Android - Bundle

 
Vista:
Imágen de perfil de tesi

Bundle

Publicado por tesi (8 intervenciones) el 13/11/2015 10:25:47
Hola compañeros! A ver si me podeis ayudar con esta pequeña duda. Quiero que al pulsar el botón "botonAceptar" de la Activity2 se envie la cadena "Aceptar" al TextView "resultado" de igual forma con el botón "botonRechazar". No me funciona y se me han agotado las ideas... Este es mi codigo:
Activity1 (a)
1
2
3
Bundle bundle = getIntent().getExtras();
resultado.setText(bundle.getString("ACEPTAR"));
resultado.setText(bundle.getString("RECHAZAR"))
Activity2 (b)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
botonAceptar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("ACEPTAR", "Aceptar");
Intent intent = new Intent(b.this, a.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
botonRechazar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("RECHAZAR", "Rechazar");
Intent intent = new Intent(b.this, a.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Francisco
Val: 466
Oro
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Bundle

Publicado por Francisco (358 intervenciones) el 13/11/2015 13:38:07
Activity1 (a)
1
2
Bundle bundle = getIntent().getExtras();
resultado.setText(bundle.getString("DATO"));

Activity2 (b)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
botonAceptar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("DATO", "Aceptar");
Intent intent = new Intent(b.this, a.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
botonRechazar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("DATO", "Rechazar");
Intent intent = new Intent(b.this, a.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de tesi

Bundle

Publicado por tesi (8 intervenciones) el 13/11/2015 15:08:06
Nada compañero asi tambien me sigue dando error... yo no lo comprendo y por mas que he probado cosas...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Francisco
Val: 466
Oro
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Bundle

Publicado por Francisco (358 intervenciones) el 13/11/2015 18:14:34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.a);
		Bundle bundle = getIntent().getExtras();
		TextView resultado=(TextView) findViewById(R.id.textView1);
		resultado.setText(""+ bundle.getString("DATO"));
	}
 
	public void onClick(View v) {
		Bundle bundle = new Bundle();
		bundle.putString("DATO", "Aceptar");
 
		//  Intent intent = new Intent(b.this, a.class); esa b sobra no se para que la pones
 
		Intent intent = new Intent(getApplicationContext(), a.class);
 
		intent.putExtras(bundle);
		startActivity(intent);
	}
	});
	botonRechazar.setOnClickListener(new OnClickListener() {
 
	public void onClick(View v) {
		Bundle bundle = new Bundle();
		bundle.putString("DATO", "Rechazar");
//				Intent intent = new Intent(b.this, a.class);
		Intent intent = new Intent(getApplicationContext(), a.class);
		intent.putExtras(bundle);
		startActivity(intent);
 
 
	}
});


Espero averte ayudado debes saber que debes declarar la actividad secundaria en el manifesto
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Francisco
Val: 466
Oro
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Bundle

Publicado por Francisco (358 intervenciones) el 15/11/2015 23:47:41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Actividad principal
botonVerificar.setOnClickListener(new View.OnClickListener() {
	@Override
	public void onClick(View v) {
		// intent para lanzar la activity Verificando
		Intent intent = new Intent(ComunicaActivity.this, Verificando.class);
 
 
 
		// Validacion si los campos nombre y edad estan vacios
		String nombre = escribirNombre.getText().toString();
		String edad = escribirEdad.getText().toString();
		if (nombre.isEmpty() && edad.isEmpty())
			Toast.makeText(getApplicationContext(), "Introduccir nombre y edad", Toast.LENGTH_SHORT).show();
		else if (nombre.isEmpty())
			Toast.makeText(getApplicationContext(), "Introduccir nombre", Toast.LENGTH_SHORT).show();
		else if (edad.isEmpty())
			Toast.makeText(getApplicationContext(), "Introduccir edad", Toast.LENGTH_SHORT).show();
		else {
			// Objeto para pasar informaciÓn a la activity que se lanza (activity llamada)
 
			// información pasada: clave:"NOMBRE",
			// valor=txtNombre.getText().toString()
			intent.putExtra("NOMBRE", nombre);
			// asocia información pasada al intent que lanzará la nueva activity
 
			// se lanza la activity asociada a este Intent
			startActivityForResult(intent, 2222);
		}
	}
});
 
 
 
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 
			if(requestCode==2222){
		resultado.setText("" + data.getStringExtra("DATO"));
 
	}
 
	super.onActivityResult(requestCode, resultCode, data);
}
 
 
 
// verificando.java
 
	botonAceptar.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent dato = new Intent();
			dato.putExtra("DATO","Aceptar");
			setResult(RESULT_OK,dato);
			finish();
		}
	});
 
	// comportamiento onClick del boton rechazar
	botonRechazar.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
 
			Intent dato = new Intent();
			dato.putExtra("DATO","Rechazar");
			setResult(RESULT_OK,dato);
			finish();
 
 
		}
	});


Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar