Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable click after clicking the textview

I have a TextView and I put a OnClickListener on this TextView. I use this action to load custom view onto a LinearLayout.

But when I click on this TextView twice, custom view is repeating on the LinearLayout. I clear all custom views on this LinearLayout before I load new custom views on to this LinearLaout.

This is my OnClickListener on TextView,

TextView rejectedTitleTextView = (TextView) findViewById(R.id.roster_menu_rejected_title);

rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rejectedTitleTextView.setBackgroundColor(getResources().getColor(R.color.acceptedPurpleColour));
                newTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
                acceptedTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));

                locationLinearLayout.removeAllViews();
                rosterBottomLayout.setVisibility(View.GONE);

                Log.d("CHECK_ACTION"," REJECTED_TEXT_VIEW ");

                InternetConnectivity internetConnectivity = new InternetConnectivity();
                final boolean isConnectedToInternet = internetConnectivity.isConnectedToInternet(context);

                if(isConnectedToInternet==true) {
                    try {
                        Thread.sleep(1300);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    getDataFromServer("REJECTED");
                }else{
                        Snackbar.make(mainView, "No Internet Connection", Snackbar.LENGTH_LONG)
                                .setAction("Action", null).show();
                }

            }
        });

getDataFromServer("REJECTED");

is the method which I used to load custom view onto this LinearLayout.

How can I prevent this issue ?

Have any ideas ?

like image 655
Terance Wijesuriya Avatar asked Nov 28 '22 22:11

Terance Wijesuriya


2 Answers

Inside onclickListener put

rejectedTitleTextView.setClickable(false);

and once finish your functionality make it as true because u need to click for next time .

rejectedTitleTextView.setClickable(true);
like image 50
Rajasekher reddy Avatar answered Dec 04 '22 14:12

Rajasekher reddy


Inside setOnclickListener try below code:-

textView.setClickable(false);
like image 25
Nitin Patel Avatar answered Dec 04 '22 14:12

Nitin Patel