0

I have this!

main activity:

public class Costo_Productos extends AppCompatActivity 


    Button agregar_articulo_btn;
    ArrayList<String> nombre_compra;
    ArrayList<Integer> cantidad_deseada;
    ArrayList<Integer> precio;
    ArrayList<Integer> total;

    ListView compras;

    lista_de_compras_adapter adapter;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_costo__productos);

        agregar_articulo_btn = (Button)findViewById(R.id.agregar_btn);

        compras = (ListView)findViewById(R.id.lista_de_compras);

        nombre_compra = new ArrayList<>();

        cantidad_deseada = new ArrayList<>();

        precio = new ArrayList<>();

        total = new ArrayList<>();

        adapter = new lista_de_compras_adapter(getApplicationContext(), R.layout.custom_lista_de_compras);

        compras.setAdapter(adapter);

        // usar bundle para recibir la informacion

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();

        if (extras!=null){

            String nombre = extras.getString("Nombre");
            int precio_producto = extras.getInt("Precio");
            int cantidad = extras.getInt("Cantidad");
            int total_pagar = extras.getInt("Total");


            nombre_compra.add(nombre);
            cantidad_deseada.add(cantidad);
            precio.add(precio_producto);
            total.add(total_pagar);

//*******************// error start here

            int i=0;

           for (String Nombre_compra : nombre_compra){

               lista_de_compras_composicion object = new lista_de_compras_composicion(nombre_compra.get(i), cantidad_deseada.get(i), precio.get(i), total.get(i));
               adapter.add(object);
               i++;
           }

//****************// error finish here

            Toast.makeText(getApplicationContext(),""+nombre+" "+precio_producto+" "+cantidad+" "+total_pagar, Toast.LENGTH_LONG).show();
        }
    }

    public void buscar_articulos (View view){

        Intent lista_art = new Intent(this, lista_de_objetos.class);
        startActivity(lista_art);

    }

The place where I take the information:

public class lista_de_cornisas_disponibles extends AppCompatActivity implements Response.Listener<String> {

    final String TAG = this .getClass().getSimpleName();
    ListView lista_cornisas_disponibles;

    int cornisa_seleccionada;
    int Precio_unidad;
    int cantidad_deseada;
    String Tipo;

    ArrayList<String> nombre_cornisa = new ArrayList<String>();
    ArrayList<Integer> disponibles = new ArrayList<Integer>();
    ArrayList<Integer> precio = new ArrayList<Integer>();
    FrameLayout frameLayout;
    LayoutInflater layoutInflater;
    PopupWindow popupWindow;

    TextView nombre_seleccionado;
    char bandera='f';


public void accion_al_seleccionar_cornisa(int cornisa_seleccionada, ArrayList<String> nombre_cornisa, ArrayList<Integer> disponibles){


    switch (cornisa_seleccionada){

        case 0:

            abrir_fragment();
            nombre_seleccionado.setText(nombre_cornisa.get(0));
            Toast.makeText(getApplicationContext(),"bandera = "+bandera, Toast.LENGTH_SHORT).show();
            Toast.makeText(getApplicationContext(),"seleccionada: "+nombre_cornisa.get(0)+""+disponibles.get(0)+""+precio.get(0),Toast.LENGTH_SHORT).show();break;

        case 1:

            abrir_fragment();
            nombre_seleccionado.setText(nombre_cornisa.get(1));
            Toast.makeText(getApplicationContext(),"seleccionada: "+nombre_cornisa.get(1)+""+disponibles.get(1),Toast.LENGTH_SHORT).show();break;

        case 2:

            abrir_fragment();
            nombre_seleccionado.setText(nombre_cornisa.get(2));
            Toast.makeText(getApplicationContext(),"seleccionada: "+nombre_cornisa.get(2)+""+disponibles.get(2),Toast.LENGTH_SHORT).show();break;

        case 3:

            abrir_fragment();
            nombre_seleccionado.setText(nombre_cornisa.get(3));
            Precio_unidad = 2000;
            Tipo = "Café Delgada";
            Toast.makeText(getApplicationContext(),"seleccionada: "+nombre_cornisa.get(3)+disponibles.get(3),Toast.LENGTH_SHORT).show();break;

    }
}


public void abrir_fragment(){

    bandera='f';

    layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    ViewGroup container = (ViewGroup) layoutInflater.inflate(R.layout.fragment_custom_seleccionar_cantidad, null);
    popupWindow = new PopupWindow(container, 300, 500, true);
    popupWindow.setWidth(FrameLayout.LayoutParams.MATCH_PARENT);
    popupWindow.showAtLocation(frameLayout, Gravity.NO_GRAVITY, 400, 1300);
    final EditText editText = (EditText)container.findViewById(R.id.cantidad);
    Button aceptar = (Button)container.findViewById(R.id.boton_aceptar);

    nombre_seleccionado = (TextView)container.findViewById(R.id.nombre_seleccion);

    aceptar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (editText.getText().toString().isEmpty()){

                Toast.makeText(getApplicationContext(), "Por favor digite la cantidad que desea obtener!", Toast.LENGTH_LONG).show();
            }
            else {

                bandera = 'v';

                cantidad_deseada = Integer.parseInt(editText.getText().toString());

                Toast.makeText(getApplicationContext(), "" + cantidad_deseada, Toast.LENGTH_SHORT).show();

                Toast.makeText(getApplicationContext(), "Bandera = " + bandera, Toast.LENGTH_SHORT).show();

                aceptar_precionado();

            }
        }
    });

}


public void aceptar_precionado(){

    // cornisa_seleccionada es la posicion

    if (bandera=='v'){


        Intent intent = new Intent(getApplicationContext(), Costo_Productos.class);
        intent.putExtra("Nombre", nombre_cornisa.get(cornisa_seleccionada));
        intent.putExtra("Precio", precio.get(cornisa_seleccionada));
        intent.putExtra("Cantidad", cantidad_deseada);
        intent.putExtra("Total", (precio.get(cornisa_seleccionada) * cantidad_deseada));
        startActivity(intent);


    }
    }
}

the composition of the row

public class lista_de_compras_composicion {

    private String Nombre;
    private int Cantidad;
    private int Precio;
    private int Total;



    public lista_de_compras_composicion(String nombre, int cantidad, int precio, int total) {

        this.setNombre(nombre);
        this.setCantidad(cantidad);
        this.setPrecio(precio);
        this.setTotal(total);
    }

    public String getNombre() {
        return Nombre;
    }

    public void setNombre(String nombre) {
        Nombre = nombre;
    }

    public int getCantidad() {
        return Cantidad;
    }

    public void setCantidad(int cantidad) {
        Cantidad = cantidad;
    }

    public int getPrecio() {
        return Precio;
    }

    public void setPrecio(int precio) {
        Precio = precio;
    }

    public int getTotal() {
        return Total;
    }

    public void setTotal(int total) {
        Total = total;
    }    
}

The adapter class

public class lista_de_compras_adapter extends ArrayAdapter {

    private List list = new ArrayList();

    public lista_de_compras_adapter(Context context, int resource) {
        super(context, resource);
    }

    public void add(lista_de_compras_composicion object) {
        list.add(object);
        super.add(object);
    }


    static class ImgHolder{

        TextView Nombre;
        TextView Cantidad;
        TextView Precio;
        TextView Total;
    }


@Override
public int getCount() {
    return this.list.size();
}

@Override
public Object getItem(int position) {
    return this.list.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View fila;
    fila = convertView;
    ImgHolder holder;

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        fila = inflater.inflate(R.layout.custom_lista_de_compras, parent, false);
        holder = new ImgHolder();
        holder.Nombre = (TextView) fila.findViewById(R.id.nombre_del_producto);
        holder.Cantidad = (TextView) fila.findViewById(R.id.cantidad);
        holder.Precio = (TextView) fila.findViewById(R.id.precio);
        holder.Total = (TextView) fila.findViewById(R.id.precio_total_producto);
        fila.setTag(holder);

    }
    else {

        holder = (ImgHolder) fila.getTag();

    }

    lista_de_compras_composicion lista_comp = (lista_de_compras_composicion) getItem(position);
    holder.Nombre.setText(lista_comp.getNombre());
    holder.Cantidad.setText(lista_comp.getCantidad());
    holder.Precio.setText(lista_comp.getPrecio());
    holder.Total.setText(lista_comp.getTotal());
    return fila;
}
}

the xml file of custom list:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60sp"
tools:context=".lista_de_tablillas_disponibles">


<TextView
    android:id="@+id/nombre_del_producto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="20dp"
    android:text="Nombre del producto"
    android:textSize="16sp" />

<TextView
    android:id="@+id/cantidad"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Cantidad"
    android:layout_marginRight="5sp"
    android:layout_alignBaseline="@+id/por"
    android:layout_alignBottom="@+id/por"
    android:layout_toLeftOf="@+id/por"
    android:layout_toStartOf="@+id/por" />


<TextView
    android:id="@+id/por"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" x "
    android:layout_marginRight="5sp"
    android:layout_alignBaseline="@+id/precio"
    android:layout_alignBottom="@+id/precio"
    android:layout_toLeftOf="@+id/precio"
    android:layout_toStartOf="@+id/precio" />


<TextView
    android:id="@+id/precio"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="11dp"
    android:text="Precio" />



<TextView
    android:id="@+id/precio_total_producto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/nombre_del_producto"
    android:text="Precio total" />

and the xml file where the list should go

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:orientation="vertical"
tools:context="Costo_Productos">

<!-- TODO: Update blank fragment layout -->
<TextView
    android:layout_width="match_parent"
    android:layout_height="30sp"
    android:background="@color/colorAccent"
    android:gravity="fill_vertical"
    android:text="@string/articulos"
    android:textColor="@android:color/background_dark"
    android:textSize="16sp" />

<Button
    android:id="@+id/agregar_btn"
    android:layout_width="match_parent"
    android:layout_height="50sp"
    android:background="@android:color/background_light"
    android:drawableLeft="@mipmap/ic_launcher"
    android:gravity="fill"
    android:text="   Agregar articulo"
    android:onClick="buscar_articulos"/>

<ListView
    android:id="@+id/lista_de_compras"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="30sp"
    android:background="@color/colorAccent"
    android:gravity="fill_vertical"
    android:text="Total:"
    android:textColor="@android:color/background_dark"
    android:textSize="16sp" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/total_parcial_txt"
        android:layout_width="90sp"
        android:layout_height="30sp"
        android:layout_alignLeft="@+id/flete_txt"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/flete_txt"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="Total parcial: " />

    <TextView
        android:id="@+id/flete_txt"
        android:layout_width="90sp"
        android:layout_height="30sp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/total_parcial_txt"
        android:layout_marginLeft="11dp"
        android:layout_marginStart="11dp"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="Flete: " />

    <TextView
        android:id="@+id/total_pagar_txt"
        android:layout_width="90sp"
        android:layout_height="30sp"
        android:layout_alignLeft="@+id/flete_txt"
        android:layout_alignStart="@+id/flete_txt"
        android:layout_below="@+id/flete_txt"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="Total a pagar: " />

    <TextView
        android:id="@+id/total_parcial_resultado"
        android:layout_width="wrap_content"
        android:layout_height="30sp"
        android:layout_alignLeft="@+id/flete_resultado"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/flete_resultado"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="colones " />

    <TextView
        android:id="@+id/flete_resultado"
        android:layout_width="wrap_content"
        android:layout_height="30sp"
        android:layout_alignLeft="@+id/total_pagar_resultado"
        android:layout_alignStart="@+id/total_pagar_resultado"
        android:layout_below="@+id/total_parcial_resultado"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="colones " />

    <TextView
        android:id="@+id/total_pagar_resultado"
        android:layout_width="wrap_content"
        android:layout_height="30sp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/flete_resultado"
        android:layout_marginEnd="12dp"
        android:layout_marginRight="12dp"
        android:layout_weight="1"
        android:gravity="fill"
        android:text="colones " />
</RelativeLayout>

The result of the Android Monitor

HostConnection::get() New Host Connection established 0x9c51ac00, tid 6159
07-03 19:52:18.036 5660-5660/com.example.juan.sdfnsdfnskdfnskdfmsfd 
W/ResourceType: No package identifier when getting value for resource number 
0x00000002
07-03 19:52:18.037 5660-5660/com.example.juan.sdfnsdfnskdfnskdfmsfd 
D/AndroidRuntime: Shutting down VM
07-03 19:52:18.050 5660-5660/com.example.juan.sdfnsdfnskdfnskdfmsfd 
E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.juan.sdfnsdfnskdfnskdfmsfd, PID: 5660

android.content.res.Resources$NotFoundException: String resource ID #0x2

at android.content.res.Resources.getText(Resources.java:335)

at android.widget.TextView.setText(TextView.java:4555)

at 

com.example.juan.sdfnsdfnskdfnskdfmsfd.lista_de_compras_adapter
.getView(lista_de_compras_adapter.java:80)

at android.widget.AbsListView.obtainView(AbsListView.java:2363)

at android.widget.ListView.measureHeightOfChildren(ListView.java:1326)

at android.widget.ListView.onMeasure(ListView.java:1233)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at 
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)

at 

android.support.v7.widget.ContentFrameLayout.
onMeasure(ContentFrameLayout.java:139)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at 

android.support.v7.widget.ActionBarOverlayLayout.
onMeasure(ActionBarOverlayLayout.java:393)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at 
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)

at android.view.View.measure(View.java:19857)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)

at com.android.internal.policy.DecorView.onMeasure(DecorView.java:689)

at android.view.View.measure(View.java:19857)

at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275)

at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1366)

at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619)

at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)

at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)

at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)

at android.view.Choreographer.doCallbacks(Choreographer.java:686)

at android.view.Choreographer.doFrame(Choreographer.java:621)

at 
android.view.Choreographer$FrameDisplayEventReceiver.
run(Choreographer.java:860)

at android.os.Handler.handleCallback(Handler.java:751)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6119)

at java.lang.reflect.Method.invoke(Native Method)

at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
run(ZygoteInit.java:886)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
07-03 19:52:18.133 5660-5665/com.example.juan.sdfnsdfnskdfnskdfmsfd I/art: 
Do partial code cache collection, code=230KB, data=163KB
07-03 19:52:18.133 5660-5665/com.example.juan.sdfnsdfnskdfnskdfmsfd I/art: 
After code cache collection, code=225KB, data=160KB
07-03 19:52:18.133 5660-5665/com.example.juan.sdfnsdfnskdfnskdfmsfd I/art: 
Increasing code cache capacity to 1024KB
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
juan
  • 43
  • 8
  • What exactly is the error? Can you show a [mcve]? – OneCricketeer Jul 02 '17 at 22:03
  • Your Arraylist are all empty, so I don't know what you expect from `nombre_compra.get(i)`, for example, other than an error – OneCricketeer Jul 02 '17 at 22:05
  • but is supposed that nombre_compra.get(i) obtein the data from here! if (extras!=null){ String nombre = extras.getString("Nombre"); int precio_producto = extras.getInt("Precio"); int cantidad = extras.getInt("Cantidad"); int total_pagar = extras.getInt("Total"); nombre_compra.add(nombre); cantidad_deseada.add(cantidad); precio.add(precio_producto); total.add(total_pagar); – juan Jul 02 '17 at 22:17
  • the thing is that Im pasing the information of the product selected from the lista_de_cornisa_disponible.Class to Costo_producto.Class. The information pass correctly because I make a toast of the arraylist nombre_compra.get(i) and is ok. But if I try to pass that information to a custom listview the app stop. And I dont know what's going on!! – juan Jul 02 '17 at 22:37
  • the other thing that I just see is that the app stop then try to add the information to the adapter lista_de_compras_adapter – juan Jul 02 '17 at 22:52
  • We can't help if you don't tell us the actual error. https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – OneCricketeer Jul 02 '17 at 23:05
  • Other than not being English, I'm sorry, but your code is difficult to read. See Java naming conventions. Classes should be `CamelCase`. No underscores. Always start with capital letters. Other variables are `lowerCamelCase`. If you want others to read and understand your code, you'd use those – OneCricketeer Jul 02 '17 at 23:08
  • yea sorry for that!! Is that Im knew in this things and how its appears in the video I put in the same way!! – juan Jul 03 '17 at 16:22
  • The thing that I want to do is like a shopping list of the items selected!! the items are in the java file call lista_de_tablillas_disponibles and they are in a listview. when I click on one of those a windows popup saying "Enter the amount you want" when a buttom is clicked, the name, mount, price, the result of multiply price per mount go to Costo_productos.java and each one goes to ther corresponding ArrayList. So everything is fine there.With that information is supposed to be added in a row of the custom list. The form of the row is in custom_lista_de_compras.xml – juan Jul 03 '17 at 16:41
  • I create an adapter call lista_de_compras_adapter.java The text view that are in Imgholder are the name, cuantity, price and total. Also made an other java file call lista_de_compras_composicion, in the video call that file row of the list. and again it has the name, cuantity, price and the total, whith the constuctor and the gatters and setters, everithing is exactly the same like in the video the thing that I change is that I put the texts of each row on Costo_productos. java file like – juan Jul 03 '17 at 16:55
  • lista_de_compras_composicion object = new lista_de_compras_composicion(nombre_compra.get(i), cantidad_deseada.get(i), precio.get(i), total.get(i)); being lista_de_compras_composicion the row of the list in java, until here the app runs fine but if I add to lista_de_compras_adapter that call adapter in Costo_producto.java the new row the app stop!! and I dont know why!! – juan Jul 03 '17 at 17:00
  • If you dont understand me, do you know how to make a custom listview with the type of data inside of the arraylists name, price, cuantity, and total?? – juan Jul 03 '17 at 17:03
  • Once more. If the app stops. [Tell us the **error**](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). Otherwise, see if this helps. https://guides.codepath.com/android/Using-an-ArrayAdapter-with-ListView#using-a-custom-arrayadapter – OneCricketeer Jul 03 '17 at 17:23
  • sorry is that I already understand what you asking for!! added!! – juan Jul 03 '17 at 20:55
  • Look at the duplicate posts, then look at your code in `getView(lista_de_compras_adapter.java:80)`, which means line 80 of that file in the getView method – OneCricketeer Jul 03 '17 at 21:44
  • and which ones are the duplicate post, I discovered that when I just leave name after line 80 and it works at least ones but just with the names!! – juan Jul 04 '17 at 05:47
  • This post is a duplicate. You've called setText using an integer and expecting the text to be that number value – OneCricketeer Jul 04 '17 at 18:14
  • awesome!! finally it appears what It should be in the listview, but the problem now is that if I add something else, just appear the new product but the previous one disappears!! why does it happen? – juan Jul 04 '17 at 18:48
  • Im using an other code that is supposed to do the same but dont increase the numbers of rows of the custom listview when add new product!! code added – juan Jul 04 '17 at 20:45
  • Please create a new question, not replace it if you have a new problem – OneCricketeer Jul 04 '17 at 23:25

0 Answers0