I'm not sure offhand why this crashes, but it could be any number of
reasons...  If you could post the logcat output, that would be very helpful.

Also, I was wondering what you were trying to accomplish with this?  If you
are trying to change the image when a touch event occurs and then have it
change back when the touch event is done, you may want to consider using a
selector drawable instead...

It allows you to specify a single drawable that will change based on the
state of the object... i.e. onFocus, onPressed, etc....

I just barely figured out how to do that and there wasn't a whole lot of
documentation available.  If that is what you are trying to do I will post
again with how to do that...

Thanks,
Justin

----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------


On Fri, Sep 4, 2009 at 12:49 AM, SAnandNarayan <anandnarayan...@gmail.com>wrote:

>
> When The Image 'a' is touched , the application chrashes , i am only
> changing the ImageResouce from 'a' to 'c' ..Here is the code
>
>
>
> public class Teach extends Activity {
>    /** Called when the activity is first created. */
>        LinearLayout mLinearLayout;
>        ImageView a;
>
>    @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;
>
>        mLinearLayout = new LinearLayout(this);
>        mLinearLayout.setOrientation(LinearLayout.VERTICAL);
>
>
>        a = new ImageView(this);
>
>
>        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));
>       LayoutParams.WRAP_CONTENT));
>
>        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;
>
>                }
>
>
>    };
> }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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