Barrier Barrier - 1 year ago 41
Android Question

Android: How to prevent click action after click once on a 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 ?

Answer Source

Inside onclickListener put

rejectedTitleTextView.setClickable(false);

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

rejectedTitleTextView.setClickable(true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download