I am just starting in programming in android studio, and I was working with spinners, where I have already created a DAO / DTO with the values I want to show. I have 3 spinners that show the sensor, the proof of this and its status. The idea is that when selecting the 3, the id of these 3 is saved in a common table called "DetailSupport", and from there, you can request the selected name through the id that is saved, and print them in a ListView.
This is my DAO
<i>
public class DetalleSoporteService {
public static List<DetalleSoporte> listaDetalleSoporte = new ArrayList<DetalleSoporte>();
public DetalleSoporteService() {
}
public void insertarDetallesoporte(DetalleSoporte detalle_soporte){
}
public void actualizarDetallesoporte (DetalleSoporte detalle_soporte){
}
public List<DetalleSoporte> obtenerDetallesoporte(){
return this.listaDetalleSoporte;
}
public void eliminarDetallesoporte(int id){
}
public void eliminarDetallesoporte(DetalleSoporte detalle_soporte){
this.eliminarDetallesoporte(detalle_soporte.getId_detalle_soporte());
}
}
</i>
My DTO
<i>
public class DetalleSoporte {
private int Id_detalle_soporte;
private int Id_soporte;
private int Id_prueba;
private int Id_sensor;
private int Id_usuario;
private int Id_estado_prueba;
public int getId_estado_prueba() {
return Id_estado_prueba;
}
public void setId_estado_prueba(int id_estado_prueba) {
Id_estado_prueba = id_estado_prueba;
}
public DetalleSoporte() {
}
public int getId_detalle_soporte() {
return Id_detalle_soporte;
}
public void setId_detalle_soporte(int id_detalle_soporte) {
Id_detalle_soporte = id_detalle_soporte;
}
public int getId_soporte() {
return Id_soporte;
}
public void setId_soporte(int id_soporte) {
Id_soporte = id_soporte;
}
public int getId_prueba() {
return Id_prueba;
}
public void setId_prueba(int id_prueba) {
Id_prueba = id_prueba;
}
public int getId_sensor() {
return Id_sensor;
}
public void setId_sensor(int id_sensor) {
Id_sensor = id_sensor;
}
public int getId_usuario() {
return Id_usuario;
}
public void setId_usuario(int id_usuario) {
Id_usuario = id_usuario;
}
public DetalleSoporte(int id_detalle_soporte, int id_soporte, int id_prueba, int id_sensor, int id_usuario, int id_estado_prueba) {
Id_detalle_soporte = id_detalle_soporte;
Id_soporte = id_soporte;
Id_prueba = id_prueba;
Id_sensor = id_sensor;
Id_usuario = id_usuario;
Id_estado_prueba = id_estado_prueba;
}
public String toString(){
return String.valueOf(Id_detalle_soporte);
}
}</i>
My view.Java, where is the list
<i>
public class vista extends AppCompatActivity {
ListView listadomostrar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vista);
this.listadomostrar = (ListView) findViewById(R.id.listadoMostrarSensores);
this.llenarList();
this.definirAccionListado();
}
private void definirAccionListado() {
try {
this.listadomostrar.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(vista.this, mostrar.class);
intent.putExtra("posicion", i);
startActivity(intent);
}
});
} catch (Exception ex) {
Toast.makeText(this, "EX: " + ex.toString(), Toast.LENGTH_SHORT).show();
}
}
private void llenarList(){
try {
ArrayAdapter<DetalleSoporte> adapter = new ArrayAdapter<DetalleSoporte>(
this, android.R.layout.simple_list_item_1, DetalleSoporteService.listaDetallesoporte);
this.listadomostrar.setAdapter(adapter);
} catch (Exception ex) {
Toast.makeText(this, "EX: " + ex.toString(), Toast.LENGTH_LONG).show();
}
}
}</i>
The view.XML
<i>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.eduar.soporte.vista"
tools:showIn="@layout/activity_vista">
<ListView
android:id="@+id/listadoMostrarSensores"
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</i>
show.java
<i>
public class mostrar extends AppCompatActivity {
TextView sensorv, pruebav, estadov;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mostrar);
this.sensorv = (TextView) findViewById(R.id.sensorview);
this.pruebav = (TextView) findViewById(R.id.pruebaview);
this.estadov = (TextView) findViewById(R.id.estadoview);
this.llenarInfo();
}
private void llenarInfo() {
try {
Intent intent = getIntent();
DetalleSoporte detalleSoporte = DetalleSoporteService.listaDetalleSoporte.get(intent.getIntExtra("posicion", 0));
this.sensorv.setText(DetalleSoporte.getId_sensor());
this.pruebav.setText(DetalleSoporte.getId_prueba());
this.estadov.setText(DetalleSoporte.getId_estado_prueba());
} catch (Exception ex) {
Toast.makeText(this, "Ex: " + ex.toString(), Toast.LENGTH_LONG).show();
}
}
}</i>
show.xml
<i>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.eduar.soporte.mostrar"
tools:layout_editor_absoluteY="25dp"
tools:showIn="@layout/activity_mostrar">
<TextView
android:id="@+id/sensorview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/pruebaview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="17dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView13" />
<TextView
android:id="@+id/estadoview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView14" />
</android.support.constraint.ConstraintLayout></i>