Wie programmgesteuert festgelegt drawableLeft auf Android-button?

Ich bin dynamisch erstellen von Schaltflächen. Ich stylte Sie mit XML erste, und ich bin versucht, den XML-unten und machen es programattic.

<Button
    android:id="@+id/buttonIdDoesntMatter"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="buttonName"
    android:drawableLeft="@drawable/imageWillChange"
    android:onClick="listener"
    android:layout_width="fill_parent">
</Button>

Dies ist, was ich habe, so weit. Ich kann alles tun, aber die drawable.

linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
    new LayoutParams(
        android.view.ViewGroup.LayoutParams.FILL_PARENT,         
        android.view.ViewGroup.LayoutParams.WRAP_CONTENT
    )
);      

linear.addView(button);

InformationsquelleAutor der Frage | 2010-12-21

Schreibe einen Kommentar