0

I want to set the image named "pic" in the ImageView as long as the screen is touched. I am a beginner and don't what the code should be in the cases of MotionEvent , can someone help me with this. This is my code:

      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frame);

        fl = (FrameLayout)findViewById(R.id.titlescreenframe);


        screen=(ImageView)findViewById(R.id.imageView1);

        fl.setOnTouchListener(new View.OnTouchListener() {





            @Override public boolean onTouch(View v, MotionEvent event) {
                switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:

                    //WHAT CODE SHOULD BE HERE

                    break;
                case MotionEvent.ACTION_UP:

                    //WHAT CODE SHOULD BE HERE

                    break;
                }
                return false;
            }








            Runnable mAction = new Runnable() {
                @Override public void run() {
                    screen.setImageResource(R.drawable.pic);

                }
            };




        });
    }
}
user2558256
  • 223
  • 3
  • 16

1 Answers1

0

In ACTION_DOWN, set the image, in ACTION_UP remove it.

Something like mTargetImageView.setImageResource(R.drawable.the_id_of_the_drawable_to_set); and to remove it something like mTargetImageView.setImageBitmap(null);

You can get the reference to the ImageView you declared in xml in onFinishInflate if the view is loaded through xml. This is something like

mTargetImageView = (ImageView) findViewById(R.id.the_id_you_gave_it_in_the_xml_file);

nickmartens1980
  • 1,593
  • 13
  • 23