Reputation: 1986
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 ?
Upvotes: 4
Views: 13098
Reputation: 383
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);
Upvotes: 13
Reputation: 2117
You can maintain boolean value like this
boolean isClick=false;
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!isClick)
{
//do your Stuff on onCLick
isClick=true;
}else
{
//leave it blank if you do not want to do anything second time
}
}
});
Upvotes: 1
Reputation: 11477
Try this
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSpinner.setEnabled(false);
mSpinner.postDelayed(new Runnable() { @Override public
void run() {
mSpinner.setEnabled(true); }
}
// do your stuff here
});
Upvotes: 3
Reputation: 1651
Inside setOnclickListener
try below code:-
textView.setClickable(false);
Upvotes: 5