Comment puis-je ajouter des images à un LinearLayout programmically?

Il y a un LinearLayout et certains Boutons dans mon projet. Je veux lors de chaque Bouton cliqué sur ajouter une petite image pour LinearLayout de drawable. Comment puis-je ajouter une image à un LinearLayout programmically?

C'est mon LinearLayout dans un HorizontalScrollView:

     <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center"
        >

        <LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >


        </LinearLayout>
    </HorizontalScrollView>

et voici mon activité:

public class MainActivity extends Activity
{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

            final LinearLayout notes = (LinearLayout)  findViewById(R.id.LinearLayout_notes);
            final  ImageView notes_do = new ImageView(this);
            notes_do.setBackgroundResource(R.drawable.notes_do);

    new Thread(new Runnable() {
        @Override
        public void run() {

    final ImageButton img_1 = (ImageButton) findViewById(R.id.img_1_);
    img_1.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

        if( event.getAction() ==  MotionEvent.ACTION_DOWN ) {

              notes.addView(notes_do);

        }
            return true;
        } 

       });  //end of ontouch

           }
          }).start(); //end of thread      


} //end of oncreate
}//end of activity

Merci.

OriginalL'auteur Mahdi Jafarzadeh | 2013-01-29