Maxie Posted January 13, 2013 Share Posted January 13, 2013 Bonjour, J'ai une question toute simple : Comment puis-je modifier la source d'un ImageView lors d'un Click sur un ToggleButton ? Voici ma déclaration de l'ImageView dans le XML : <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="ToggleButton" /> <ImageView android:id="@+id/img" android:layout_below="@+id/toggleButton1" android:src="@drawable/ame" android:layout_marginTop="40dp" android:layout_centerHorizontal="true"/> </RelativeLayout> Et l'instanciation des objets puis de l'écouteur Click dans le .java public class MainActivity extends Activity { ToggleButton btn; ImageView img1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (ToggleButton) findViewById(R.id.toggleButton1); img1 = (ImageView) findViewById(R.id.img); btn.setonclickListener(new View.onclickListener() { public void onclick(View v) { //Je ne sais quelle propriété modifier pour accéder à la source de img1 img1. } }); } Merci de votre aide. Bonne journée. Link to comment Share on other sites More sharing options...
ygort Posted January 15, 2013 Share Posted January 15, 2013 Tu en as plusieurs (CF DOC) setImageBitmap, setImageDrawable, setImageURI, setImageResource pour le toggleButton, surement un setBackground(Drawable d) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.