Domanda

I have created a lot of buttons, in the java code, which represent some houses(for example). I want to create another button which is called "selection multiple". When i click on this button(selection multiple), all the others buttons(the houses) will change style or color when I click on them. The problems is that I create the buttons ( house ) in the java code so i don't find how to change their style when I click on them /:

 Button macase = new Button (this);
 macase.setText("o"+Numcase);
 tr.addView(macase);
È stato utile?

Soluzione 2

as far as I understand your problem is setting the Color of the button programatically.

You could for example do it like this:

 macase.setBackgroundColor(Color.BLUE);

Altri suggerimenti

Once you have a reference to your button object, you can change it's image or background (for example) with these functions.

    macase.setImageResource(R.drawable.myicon);
    macase.setBackgroundResource(R.drawable.mycustomButton);

In the second case, mycustomButton is an XML file with the custom style you want to apply

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top