Error al grabar en BD y pasar de pantalla
Publicado por Fernando (19 intervenciones) el 13/03/2019 16:15:32
Buenas.
Estoy haciendo una aplicacion que tiene una activity con un listview y esta llega a otra que da de alta en una tabla de una B.D. para que despues vuelva a la pantalla anterior rejenerando el listview. Pues bien cuando grabo (anadir_button)
y cuando vuelve a la pantalla anterior con rejenera el listview
¿Como puedo volver a la pantalla anterior y que vuelva a ejecutar el OnCreate ?
Estoy haciendo una aplicacion que tiene una activity con un listview y esta llega a otra que da de alta en una tabla de una B.D. para que despues vuelva a la pantalla anterior rejenerando el listview. Pues bien cuando grabo (anadir_button)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.valhondo.delgado.cofradiaadmin;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class ActivityAnadir extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anadir);
Bundle extra = getIntent().getExtras();
int parametro = extra.getInt("parametro");
LinearLayout linearLayout_grabar = (LinearLayout) findViewById(R.id.layout_botones_list);
LinearLayout linearLayout_consulta = (LinearLayout) findViewById(R.id.layout_consulta_list);
if (parametro == 1) {
linearLayout_grabar.setVisibility(View.INVISIBLE);
linearLayout_consulta.setVisibility(View.VISIBLE);
String ncorto = extra.getString("ncorto");
String nlargo = extra.getString("nlargo");
String tlef = extra.getString("tlef");
String posi = extra.getString("posi");
TextView nombreC = (TextView) findViewById(R.id.nombre_corto_edit);
TextView nombreL = (TextView) findViewById(R.id.nombre_largo_edit);
TextView telefono = (TextView) findViewById(R.id.telefono_edit);
TextView posicion = (TextView) findViewById(R.id.posicion_edit);
nombreC.setText(ncorto);
nombreL.setText(nlargo);
telefono.setText(tlef);
posicion.setText(posi);
}else{
linearLayout_grabar.setVisibility(View.VISIBLE);
linearLayout_consulta.setVisibility(View.INVISIBLE);
Button botongrabar = (Button) findViewById(R.id.anadir_button);
Button botoncancelar = (Button) findViewById(R.id.cancelar_button_anadir);
botongrabar.setOnClickListener(this);
botoncancelar.setOnClickListener(this);
}
}
@Override
public void onClick (View buttonView){
int buttonGps = buttonView.getId();
TextView nombreC = (TextView) findViewById(R.id.nombre_corto_edit);
TextView nombreL = (TextView) findViewById(R.id.nombre_largo_edit);
TextView telefono = (TextView) findViewById(R.id.telefono_edit);
TextView posicion = (TextView) findViewById(R.id.posicion_edit);
GpsProcesion gpsProcesion = new GpsProcesion();
switch (buttonGps) {
case R.id.anadir_button:
gpsProcesion.setNombrecortogps(nombreC.getText().toString());
gpsProcesion.setNombrelargogps(nombreL.getText().toString());
gpsProcesion.setTelefonogps(telefono.getText().toString());
gpsProcesion.setPosiciongps(posicion.getText().toString());
if ((gpsProcesion.getNombrecortogps().isEmpty()) || (gpsProcesion.getNombrelargogps().isEmpty()) ||
(gpsProcesion.getTelefonogps().isEmpty()) || (gpsProcesion.getPosiciongps().isEmpty())) {
Toast.makeText(this, "Los Campos no deben de estar Vacios", Toast.LENGTH_LONG).show();
} else {
// Grabar
GpsDbHelper dbhelper = new GpsDbHelper(this);
SQLiteDatabase insertarprocesion = dbhelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(InContract.GpsColumnas.NOMBRECORTO, gpsProcesion.getNombrecortogps());
contentValues.put(InContract.GpsColumnas.NOMBRELARGO, gpsProcesion.getNombrelargogps());
contentValues.put(InContract.GpsColumnas.TELEFONO, gpsProcesion.getTelefonogps());
contentValues.put(InContract.GpsColumnas.POSICION, gpsProcesion.getPosiciongps());
insertarprocesion.insert(InContract.GpsColumnas.TABLA_PROCESION, null, contentValues);
dbhelper.close();
}
break;
case R.id.cancelar_button_anadir:
onBackPressed();
break;
}
}
}
y cuando vuelve a la pantalla anterior con rejenera el listview
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
73
74
75
76
77
78
79
package com.valhondo.delgado.cofradiaadmin;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class ActivityGPS extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps);
LinearLayout LayoutGpsListView = (LinearLayout) findViewById(R.id.layout_gps_list);
Button botongrabar = (Button) findViewById(R.id.anadir_button);
botongrabar.setOnClickListener(this);
GpsDbHelper dbhelper = new GpsDbHelper(this);
SQLiteDatabase database = dbhelper.getWritableDatabase();
if (dbhelper.checkEmpty(database, InContract.GpsColumnas.TABLA_PROCESION)){
LayoutGpsListView.setVisibility(View.INVISIBLE);
}else {
LayoutGpsListView.setVisibility(View.VISIBLE);
SimpleCursorAdapter adaptador;
ListView listView = (ListView) findViewById(R.id.datos_gps_list_view);
Cursor cursor = database.rawQuery("SELECT * FROM " + InContract.GpsColumnas.TABLA_PROCESION + " ORDER BY " + InContract.GpsColumnas.POSICION, null);
String[] campos = {InContract.GpsColumnas.NOMBRELARGO};
int[] ids = {R.id.nombre_largo_list_item};
adaptador = new SimpleCursorAdapter( this, R.layout.gps_list_item, cursor, campos, ids);
listView.setAdapter(adaptador);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ActivityGPS.this, ActivityAnadir.class);
intent.putExtra("parametro", 1);
intent.putExtra("identi", InContract.GpsColumnas.IDGPS);
intent.putExtra("ncorto", InContract.GpsColumnas.NOMBRECORTO);
intent.putExtra("nlargo", InContract.GpsColumnas.NOMBRELARGO);
intent.putExtra("tlef", InContract.GpsColumnas.TELEFONO);
intent.putExtra("posi", InContract.GpsColumnas.POSICION);
startActivity(intent);
}
});
}
}
@Override
public void onClick (View buttonView){
int buttonGps = buttonView.getId();
switch (buttonGps) {
case R.id.anadir_button:
Intent intent = new Intent(ActivityGPS.this, ActivityAnadir.class);
intent.putExtra("parametro", 2);
startActivity(intent);
break;
}
}
}
¿Como puedo volver a la pantalla anterior y que vuelva a ejecutar el OnCreate ?
Valora esta pregunta
0