Android bundle other class (Adapter)

0

Good evening! I have the following situation:

case R.id.item_cep:
    corPadrao = Color.parseColor("#4DC184");
    imgCircle.setColorFilter(corPadrao);
    nomeRoteirizacao.setText("Por Cep");
    setActivityBackgroundColor(corPadrao);
    Intent intent = new Intent(getApplicationContext(),InformarEntrega.class);
    Bundle params = new Bundle();
    params.putString("cor","#4DC184");
    intent.putExtras(params);

When I click on item_cep it stores the color, but in another class (Class is Adapter) do I need to have this color how to proceed?

Am I doing it right? and how do I get this color in the adapter class?

    
asked by anonymous 02.06.2016 / 11:07

1 answer

1

Diego,

To solve your problem, create a file named colors.xml in values (if you do not).

Similar to this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <color name="White">#FFFFFF</color>
 <color name="DarkOrange">#FF8C00</color>
 <color name="WhiteSmoke">#F5F5F5</color>
 <color name="Goldenrod">#DAA520</color>
 <color name="LightGrey">#D3D3D3</color>
 <color name="DarkGray">#333333</color>
 <color name="DarkRed">#8B0000</color>
 <color name="Gray">#808080</color>
 <color name="ForestGreen">#228B22</color>
 <color name="Black">#000000</color>
</resources>

You do not need a Bundle. You could use the method in the object:

intent.putExtra("color", R.color.Gray);

To recover, in another Activity:

int resColor =  getIntent().getIntExtra("cor",0);

Zero is in case you can not recover.

This will return the integer referring to the color in class R. You will only have to assign it as you wish.

Editing: It does not make any sense to an Intent for an Adapter class.

Att,

    
02.06.2016 / 14:43