Pass variable to class cursorAdapter from activity

1

I have data loaded into a listview with custom cursorAdapter, my question is how can I pass a variable to the adapter cursor from the activity where I call the cursor, I do not know if they understand me.

Try to pass it through the constructor

mProdcutoAdapter=new SelectCursorAdapterProductos(this,null,codcabecera);

so in the adapter class

  public SelectCursorAdapterProductos(Context context, Cursor c, String cod) {
    super(context, c, 0);
    codpedido=cod;
}

but it does not assign the code to the variable that I need, the variable ordered is still in null

    
asked by Alldesign Web 17.05.2017 в 00:10
source

2 answers

0
  

Pass variable to cursorAdapter class from activity

This must be when instantiating your Adapter, you can modify the constructor to receive the variable and be used in the Adapter, for example:

private String valor;

 public SelectCursorAdapterProductos(Context context, Cursor c, String cod, String valor) {
    super(context, c, 0);
    codpedido=cod;
    //valor recibido a travez del constructor.
    this.valor = valor;
}

therefore when instantiating your Adapter in your Activity you send the value:

mProdcutoAdapter = new SelectCursorAdapterProductos(this,null,codcabecera, "Alldesign Web");

What you do is correct, simply that codcabecera has value null !, verify that when instantiating the Adapter the value of codcabecera is correct.

    
answered by 17.05.2017 / 00:20
source
0

Probably this is not the correct answer but it worked for me very well when passing a variable from the Activity to the Adapter

Activity---
    public static String mInfoFoto;
       ejemplo 1.- (mInfoFoto = getIntent().getExtras().getString(EXTRA_BOLEAN_PICTURE);)
       ejemplo 2 = mInfoFoto = "HolaMundo"

   public static String getMyVariablePicture() {
        return mInfoFoto;
    }
------
Adapter

    private String getVariableBolean = MainMultimediaActivity.getMyVariablePicture();
    
answered by 17.05.2017 в 00:47