-1

I am trying to close view by using cross image(cancel_video_image_view in the code) which is at the top right of the screen as seen in the image demo image. it is working for first time but fail to work for second time, why set on click listener not working for second time inside running thread?please help: demo image this is the code

@Override 
public void onTargetRecognized(final Tracker tracker_, final String targetName_) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (targetName_.toString().equalsIgnoreCase("TargetOne")) {
                LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
                LinearLayout controls = (LinearLayout) inflater.inflate(R.layout.one_video_gallery, null);
                viewHolder.addView(controls);
                info_one_video_gallery = (TextView)findViewById(R.id.info_one_video_gallery);
                monument_name_one_video_gallery = (TextView)findViewById(R.id.monument_name_one_video_gallery);
                one_video_gallary_imageview = (ImageView)findViewById(R.id.one_video_gallary_imageview);
                one_video_gallary_thumbnail = (ImageView)findViewById(R.id.one_video_gallary_thumbnail);
                final ImageView cancel_video_image_view= (ImageView)findViewById(R.id.cancel_video_image_view);
                cancel_video_image_view.setClickable(true);


                one_video_gallary_imageview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplication(),MediaFullScreenImageActivity.class);
                        String monument_images = PropertyFile.TargetOne + "_images";
                        intent.putExtra("monument_images",monument_images);
                        startActivity(intent);
                    }
                });

                one_video_gallary_thumbnail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), MediaVideoActivity.class);
                        String monument = PropertyFile.TargetOne;
                        intent.putExtra("monument", monument);
                        String monument_images = PropertyFile.TargetOne + "_images";
                        intent.putExtra("monument_images", monument_images);
                        startActivity(intent);

                    }
                });


                if(cancel_video_image_view.getVisibility() == View.INVISIBLE){
                    cancel_video_image_view.setVisibility(View.VISIBLE);
                    cancel_video_image_view.setClickable(true);
                    one_video_gallary_imageview.setVisibility(View.VISIBLE);
                    one_video_gallary_thumbnail.setVisibility(View.VISIBLE);
                    info_one_video_gallery.setVisibility(View.VISIBLE);
                    monument_name_one_video_gallery.setVisibility(View.VISIBLE);

                }

                cancel_video_image_view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "You clicked the button", Toast.LENGTH_SHORT).show();
                        one_video_gallary_imageview.setVisibility(View.INVISIBLE);
                        one_video_gallary_thumbnail.setVisibility(View.INVISIBLE);
                        cancel_video_image_view.setVisibility(View.INVISIBLE);
                        info_one_video_gallery.setVisibility(View.INVISIBLE);
                        monument_name_one_video_gallery.setVisibility(View.INVISIBLE);


                    }
                });

     }
Mithun Kumar
  • 595
  • 1
  • 9
  • 18
  • Along with downvoting, people should at least explain what they felt wrong with the post (spam/no-code/format/code request/etc.) – Shaishav Aug 03 '16 at 07:27

1 Answers1

0

What I think that you should not put onClickListener in the runOnUiThread. Because when onTargetRecongnized was called, it will just check if statements in short time and just finish the runnable.

luopleming
  • 28
  • 1
  • 9
  • hi @luopleming , i am using wikitude AugmentedReality sdk with android app. we must write inside runOnUiThread according to wikitude sdk. – Mithun Kumar Aug 03 '16 at 08:50
  • What about you take all those onClickListeners out of the runOnUiThread then when on of those are clicked you run runOnUiThread. – luopleming Aug 03 '16 at 11:00
  • wikitude sdk will not work properly if i do like that. – Mithun Kumar Aug 03 '16 at 17:46
  • Hmm.. eithery way this wouldn't work, so I suggest you put that code out of runOnUiThread. But it's your choice, as there maybe other ways to fix it. – luopleming Aug 04 '16 at 00:39