Sto implementando un metodo semplice per aggiungere uno a LinearLayout
in modo programmatico.Button.setBackground (Sfondo disegnabile) genera NoSuchMethodError
Quando invoco il metodo setBackground (sfondo Drawable), il seguente Error
è gettato:
java.lang.NoSuchMethodError: android.widget.Button.setBackground
mio metodo addNewButton:
private void addNewButton(Integer id, String name) {
Button b = new Button(this);
b.setId(id);
b.setText(name);
b.setTextColor(color.white);
b.setBackground(this.getResources().getDrawable(R.drawable.orange_dot));
//llPageIndicator is the Linear Layout.
llPageIndicator.addView(b);
}
Quindi, qual è la soluzione per aggiungere la sfondo del pulsante programmaticamente per abbassarsi rispetto a Api 16..withou t setBackGroundDrawable..which è deprecato ...? –
@EslamYousefMohammed ha modificato la mia risposta: prova 'setBackgroundResource'. – Mena
ho impostato android: minSdkVersion = "9" nel mio manifest, perché eclipse non mi avvisa di questo? – wutzebaer