The application crashed when I touch the Image 'a' . I just change the Image
Resource from 'a' to 'c'.Here is the code

public class Teach extends Activity {
    /** Called when the activity is first created. */
    LinearLayout mLinearLayout;
    ImageView a;
    // ImageView c ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
      int width= dm.widthPixels;
      int height=dm.heightPixels;
       // setContentView(R.layout.main);
        // Create a LinearLayout in which to add the ImageView
        mLinearLayout = new LinearLayout(this);
        mLinearLayout.setOrientation(LinearLayout.VERTICAL);

        // Instantiate an ImageView and define its properties
        a = new ImageView(this);



      //  a.onTouchEvent(event)
        a.setImageResource(R.drawable.a);
        a.setOnTouchListener(toucha);
        a.setAdjustViewBounds(true);
        a.setMaxHeight(height/2);
        a.setMaxWidth(width/2);
        a.setLayoutParams(new
Gallery.LayoutParams(android.widget.Gallery.LayoutParams.WRAP_CONTENT,android.widget.Gallery.LayoutParams.WRAP_CONTENT));
        // set the ImageView bounds to match the Drawable's dimensions
     //   i.setLayoutParams(new
Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        // Add the ImageView to the layout and set the layout as the content
view

        ImageView b = new ImageView(this);
        b.setImageResource(R.drawable.b);

        b.setAdjustViewBounds(true);
        b.setMaxHeight(100);
        b.setMaxWidth(100);
        b.setLayoutParams(new
Gallery.LayoutParams(android.widget.Gallery.LayoutParams.WRAP_CONTENT,android.widget.Gallery.LayoutParams.WRAP_CONTENT));

        mLinearLayout.addView(a);

        mLinearLayout.addView(b);

        setContentView(mLinearLayout);


    }
     OnTouchListener toucha=new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ((ImageView) v).setImageResource(R.drawable.c);



            return true;

        }


    };
}

-- 
Anand Narayan.S

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to