jueves, 5 de noviembre de 2015

Curso Android Studio: ListView con Imagenes

Curso Android Studio: ListView con Imagenes



Saludos, tengo un ActivityA coun un Spinner yn ListView, y un ActivityB con par de TextView. Lo que intento pasar desde el ActivityA son dos cosas:

  • El valor seleccionado en el Spinner
  • El valor contenido en el area del ListView a la hora de hacerle "click"
y que se impriman en los respectivos textView del ActivityB

Hasta ahora no me pasa nada. Les paso parte de mi código y unas imágenes para que sea comprensible mi problemática:


//Pedido.java--->asociado a ActivityA
public class Pedido extends Activity{
 private String[] arrayEntremeses = {"elija...","[Buñuelos]","[Nugget]","[Tartaleta]","[Tostadas]","[Sushi]"};
 private String[] arrayPlato = {"elija...","[Carne]","[Pollo]","[Pescado]","[Asado]","[GordonBlue]","[Chuleta]","[Pernil]"};
 private String[] arraySopa = {"elija...","[Menestrone]","[Pollo]","[Res]","[Pescado]","[Cruzado]","[Mondongo]"};
 private String[] arrayEnsalada = {"elija...","[Rallada]","[Cocida]","[Mixta]","[Cesar]"};
 private String[] arrayContorno = {"elija...","[Yuca]","[Bollo]","[Catalina]","[Papita]","[Arepita]"};
 private String[] arrayBebida = {"elija...","[Refresco]","[Malta]","[Jugo]","[Batido]","[Cerveza]","[Wiskie]","[Ron]","[Vino]"};
 private String[] arrayPostres = {"elija...","[Ponque]","[Brownie]","[Helado]","[Golfeado]","[Dona]"};
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.pedido);
  final TextView txVwNumPedido;// txVwMesa = null ;
  Button btnCargar = (Button) findViewById(R.id.btnPedidoCargar);
  /***Recibir Data del ListView*****/
  txVwNumPedido=(TextView) findViewById(R.id.txVwNumero);
  final Bundle bund=this.getIntent().getExtras();
  txVwNumPedido.setText(bund.getString("NumPedido"));
  /************************/
}

//OrdenNueva.java--->Asociado a ActivityB
public class OrdenNueva extends Activity /*implements ListAdapter, OnItemClickListener*/ {
 //private ArrayList<MensajeListOrdenNueva> listMensaje;
 OrdenNuevaAdapter adapterOrden;
 //private ListView lVwOrdenNueva;
 private int[] arrayRellenoIco = {R.drawable.plato,R.drawable.plato,R.drawable.plato,R.drawable.plato,R.drawable.plato,R.drawable.plato,R.drawable.plato};
 private String[] arrayOrden = {"Pedido1","Pedido2","Pedido3","Pedido4","Pedido5","Pedido6","Pedido7"};
 private String[] arrayContronoOrden = {"-","-","-","-","-","-","-"};
 Spinner spnMesa;
 EditText eTxCantPedido;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.orden_nueva);
  final Bundle bund = this.getIntent().getExtras();
  eTxCantPedido=(EditText) findViewById(R.id.editTxtCantPedido);
  eTxCedula=(EditText) findViewById(R.id.editTxtOrdenNuevaCliente);
  eTxRif=(EditText) findViewById(R.id.editTxtOrdenNuevaRif);
  spnMesa = (Spinner) findViewById(R.id.spinnerMesa);
  final ListView lVwOrdenNueva=(ListView) findViewById(R.id.listVwOrdenNueva);
  adapterOrden= new OrdenNuevaAdapter(this,arrayOrden,arrayContronoOrden,arrayRellenoIco);
  lVwOrdenNueva.setAdapter(adapterOrden);
  final Button btnSalida = (Button) findViewById(R.id.btnOrdenNuevaSalir); 
  final Button btnPrincipal = (Button) findViewById(R.id.btnOrdenNuevaPrincipal);
  final Intent intentEnviaPedido = new Intent(OrdenNueva.this, Pedido.class);
  /********** PARA LLENAR SPINNER Mesa*******/
  Spinner spinner = (Spinner) findViewById(R.id.spinnerMesa);
  ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.mesa_array,android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spinner.setAdapter(adapter);
  /************************************/
  lVwOrdenNueva.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 
    String valor =(String) adapterView.getItemAtPosition(i);
    //String posicionSpnMesa=(String) spnMesa.getSelectedItem();
    //Intent intentEnviaPedido2 = new Intent();
    //intentEnviaPedido.putExtra("NumMesa", posicionSpnMesa);
    
    if ((eTxCantPedido.length()==0)||(spnMesa.getSelectedItemId()==0)) {
     Toast toastMsjValorVacio = Toast.makeText(getApplicationContext(), "Debe seleccionar una Mesa y Cantidad de Pedidos: " , Toast.LENGTH_LONG);
     toastMsjValorVacio.show();
     }
    else{
     bund.putLong("NumPedido", spnMesa.getSelectedItemId());
     intentEnviaPedido.putExtras(bund);
     Toast toastMsjValidaMain2 = Toast.makeText(getApplicationContext(), "Mesa: "+ spnMesa.getSelectedItemId() , Toast.LENGTH_LONG);
     toastMsjValidaMain2.show(); 
     startActivity(intentEnviaPedido);
    }
            }
  });


}

<!--ActivityA=orden_nueva.xml-->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
        android:id="@id/btnOpcionesNuevaOrden"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp" >
        <TextView
            android:id="@+id/txtOrdenNuevaTitulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/titleOrdenNueva"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>
</RelativeLayout>

<!--ActivityB=pedido.xml-->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_gravity="center">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp"
        android:gravity="center" >
        <TextView
            android:id="@+id/txVwPedidoTitulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/titlePedidoNuevo" />
        <TextView
            android:id="@+id/txVwNumero"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
        <TextView
            android:id="@+id/TxVwPedidoMesa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </LinearLayout>
</RelativeLayout>

<!--Interfaz de orden_nueva.xml-->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dip"
    android:layout_gravity="center" >
    <!--  listrow  -->
        <ImageView
            android:id="@+id/ordenListaIcono"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/ic_launcher" />
        <TextView
            android:id="@+id/ordenListaTitulo1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:text="TextView"
            android:textColor="#040404"
            android:textSize="14dp"
            android:typeface="sans" />
    <!-- titulo de la categoria -->
        <TextView
            android:id="@+id/ordenListaTitulo2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:text="TextView"
            android:textColor="#040404"
            android:textSize="14dp"
            android:typeface="sans" />
</RelativeLayout>

Por favor ayudame amigo, dame una idea. llevo una semana trancado en esto, no he dado pie con bola y se me atrasa el proyecto...
Tambien te consulte por tu canal de youtube. Por favor ayuda...