limit button press to 3 times per week
I have a button that I want to limit the pressing off up to 3 times a week.
How can I track this and make sure that once it reaches its maximum no button press will happen?
Heres my basic code for the button click and count.
int count = 0;
limit_ButtonPress()
Button btn = findViewById(R.id.comp)
btn.setOnClickListener(new OnClickListener){
(View v)
count++
private void limit_ButtonPress(){
if(count> 0 && count< 5)
btn.setVisabilty(View.Invisable)
how can I now limit the 3 presses per week? Thanks, guys
java
|
show 1 more comment
I have a button that I want to limit the pressing off up to 3 times a week.
How can I track this and make sure that once it reaches its maximum no button press will happen?
Heres my basic code for the button click and count.
int count = 0;
limit_ButtonPress()
Button btn = findViewById(R.id.comp)
btn.setOnClickListener(new OnClickListener){
(View v)
count++
private void limit_ButtonPress(){
if(count> 0 && count< 5)
btn.setVisabilty(View.Invisable)
how can I now limit the 3 presses per week? Thanks, guys
java
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43
|
show 1 more comment
I have a button that I want to limit the pressing off up to 3 times a week.
How can I track this and make sure that once it reaches its maximum no button press will happen?
Heres my basic code for the button click and count.
int count = 0;
limit_ButtonPress()
Button btn = findViewById(R.id.comp)
btn.setOnClickListener(new OnClickListener){
(View v)
count++
private void limit_ButtonPress(){
if(count> 0 && count< 5)
btn.setVisabilty(View.Invisable)
how can I now limit the 3 presses per week? Thanks, guys
java
I have a button that I want to limit the pressing off up to 3 times a week.
How can I track this and make sure that once it reaches its maximum no button press will happen?
Heres my basic code for the button click and count.
int count = 0;
limit_ButtonPress()
Button btn = findViewById(R.id.comp)
btn.setOnClickListener(new OnClickListener){
(View v)
count++
private void limit_ButtonPress(){
if(count> 0 && count< 5)
btn.setVisabilty(View.Invisable)
how can I now limit the 3 presses per week? Thanks, guys
java
java
edited Nov 15 '18 at 6:13
Dang Nguyen
875522
875522
asked Nov 14 '18 at 22:12
markharropmarkharrop
319114
319114
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43
|
show 1 more comment
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43
|
show 1 more comment
1 Answer
1
active
oldest
votes
have a look at this
you want that button can only be clicked thrice a week not more than that.
so have such type of firebase database structure :
"root/" :
"users" :
"user_01" :
//some profile data about the user like name email etc.
"data" : "val"
//this is important
"signUpTime" : 1563245126 //this is the timestamp of when the user signed up
,
...
"activity" :
"user_01" :
random_id_01 :
"clickTime" : 156845164 //timestamp of click
,
...
now its responsibility to define reading and writing access to the database for users.
now comes the java/android part
private void initUI()
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("activity").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Query query = databaseReference.orderByChild("clickTime").limitToLast(3);
query.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
if(dataSnapshot.exists())
//now count the children in dataSnapshot
int totalChildren = (int) dataSnapshot.getChildrenCount();
if(totalChildren > 2)
//now check for this person properly
int milliSecInAWeek = 7*24*60*60*1000; //perhaps i m right ;)
//now check if the last of the three click was within this week
for(DataSnapshot snapshot : dataSnapshot.getChildren())
//well this is actully a loop kind of thing
//but we are just conserned about the first most click so we will call return just on the first child itteration :)
UserActivity userActivity = snapshot.getValue(UserActivity.class);
if(userActivity.getClickTime() - System.currentTimeMillis() < milliSecInAWeek)
//this person has clicked thrre times in this week disable the button buddy ;)
else
//this person has got chance(s) to click. let the button be enables :)
return;
else
//this user has clicked less then 3 times so the let the button be clickable for the user
else
//there is no activity by this user let the button be clickable
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
private class UserActivity
private float clickTime;
public UserActivity()
public UserActivity(float clickTime)
this.clickTime = clickTime;
public float getClickTime()
return clickTime;
public void setClickTime(float clickTime)
this.clickTime = clickTime;
hope it helps you and if does just accept the answer it ll help me a bit :)
happy coding !!!
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309519%2flimit-button-press-to-3-times-per-week%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
have a look at this
you want that button can only be clicked thrice a week not more than that.
so have such type of firebase database structure :
"root/" :
"users" :
"user_01" :
//some profile data about the user like name email etc.
"data" : "val"
//this is important
"signUpTime" : 1563245126 //this is the timestamp of when the user signed up
,
...
"activity" :
"user_01" :
random_id_01 :
"clickTime" : 156845164 //timestamp of click
,
...
now its responsibility to define reading and writing access to the database for users.
now comes the java/android part
private void initUI()
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("activity").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Query query = databaseReference.orderByChild("clickTime").limitToLast(3);
query.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
if(dataSnapshot.exists())
//now count the children in dataSnapshot
int totalChildren = (int) dataSnapshot.getChildrenCount();
if(totalChildren > 2)
//now check for this person properly
int milliSecInAWeek = 7*24*60*60*1000; //perhaps i m right ;)
//now check if the last of the three click was within this week
for(DataSnapshot snapshot : dataSnapshot.getChildren())
//well this is actully a loop kind of thing
//but we are just conserned about the first most click so we will call return just on the first child itteration :)
UserActivity userActivity = snapshot.getValue(UserActivity.class);
if(userActivity.getClickTime() - System.currentTimeMillis() < milliSecInAWeek)
//this person has clicked thrre times in this week disable the button buddy ;)
else
//this person has got chance(s) to click. let the button be enables :)
return;
else
//this user has clicked less then 3 times so the let the button be clickable for the user
else
//there is no activity by this user let the button be clickable
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
private class UserActivity
private float clickTime;
public UserActivity()
public UserActivity(float clickTime)
this.clickTime = clickTime;
public float getClickTime()
return clickTime;
public void setClickTime(float clickTime)
this.clickTime = clickTime;
hope it helps you and if does just accept the answer it ll help me a bit :)
happy coding !!!
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
add a comment |
have a look at this
you want that button can only be clicked thrice a week not more than that.
so have such type of firebase database structure :
"root/" :
"users" :
"user_01" :
//some profile data about the user like name email etc.
"data" : "val"
//this is important
"signUpTime" : 1563245126 //this is the timestamp of when the user signed up
,
...
"activity" :
"user_01" :
random_id_01 :
"clickTime" : 156845164 //timestamp of click
,
...
now its responsibility to define reading and writing access to the database for users.
now comes the java/android part
private void initUI()
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("activity").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Query query = databaseReference.orderByChild("clickTime").limitToLast(3);
query.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
if(dataSnapshot.exists())
//now count the children in dataSnapshot
int totalChildren = (int) dataSnapshot.getChildrenCount();
if(totalChildren > 2)
//now check for this person properly
int milliSecInAWeek = 7*24*60*60*1000; //perhaps i m right ;)
//now check if the last of the three click was within this week
for(DataSnapshot snapshot : dataSnapshot.getChildren())
//well this is actully a loop kind of thing
//but we are just conserned about the first most click so we will call return just on the first child itteration :)
UserActivity userActivity = snapshot.getValue(UserActivity.class);
if(userActivity.getClickTime() - System.currentTimeMillis() < milliSecInAWeek)
//this person has clicked thrre times in this week disable the button buddy ;)
else
//this person has got chance(s) to click. let the button be enables :)
return;
else
//this user has clicked less then 3 times so the let the button be clickable for the user
else
//there is no activity by this user let the button be clickable
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
private class UserActivity
private float clickTime;
public UserActivity()
public UserActivity(float clickTime)
this.clickTime = clickTime;
public float getClickTime()
return clickTime;
public void setClickTime(float clickTime)
this.clickTime = clickTime;
hope it helps you and if does just accept the answer it ll help me a bit :)
happy coding !!!
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
add a comment |
have a look at this
you want that button can only be clicked thrice a week not more than that.
so have such type of firebase database structure :
"root/" :
"users" :
"user_01" :
//some profile data about the user like name email etc.
"data" : "val"
//this is important
"signUpTime" : 1563245126 //this is the timestamp of when the user signed up
,
...
"activity" :
"user_01" :
random_id_01 :
"clickTime" : 156845164 //timestamp of click
,
...
now its responsibility to define reading and writing access to the database for users.
now comes the java/android part
private void initUI()
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("activity").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Query query = databaseReference.orderByChild("clickTime").limitToLast(3);
query.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
if(dataSnapshot.exists())
//now count the children in dataSnapshot
int totalChildren = (int) dataSnapshot.getChildrenCount();
if(totalChildren > 2)
//now check for this person properly
int milliSecInAWeek = 7*24*60*60*1000; //perhaps i m right ;)
//now check if the last of the three click was within this week
for(DataSnapshot snapshot : dataSnapshot.getChildren())
//well this is actully a loop kind of thing
//but we are just conserned about the first most click so we will call return just on the first child itteration :)
UserActivity userActivity = snapshot.getValue(UserActivity.class);
if(userActivity.getClickTime() - System.currentTimeMillis() < milliSecInAWeek)
//this person has clicked thrre times in this week disable the button buddy ;)
else
//this person has got chance(s) to click. let the button be enables :)
return;
else
//this user has clicked less then 3 times so the let the button be clickable for the user
else
//there is no activity by this user let the button be clickable
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
private class UserActivity
private float clickTime;
public UserActivity()
public UserActivity(float clickTime)
this.clickTime = clickTime;
public float getClickTime()
return clickTime;
public void setClickTime(float clickTime)
this.clickTime = clickTime;
hope it helps you and if does just accept the answer it ll help me a bit :)
happy coding !!!
have a look at this
you want that button can only be clicked thrice a week not more than that.
so have such type of firebase database structure :
"root/" :
"users" :
"user_01" :
//some profile data about the user like name email etc.
"data" : "val"
//this is important
"signUpTime" : 1563245126 //this is the timestamp of when the user signed up
,
...
"activity" :
"user_01" :
random_id_01 :
"clickTime" : 156845164 //timestamp of click
,
...
now its responsibility to define reading and writing access to the database for users.
now comes the java/android part
private void initUI()
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("activity").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
Query query = databaseReference.orderByChild("clickTime").limitToLast(3);
query.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
if(dataSnapshot.exists())
//now count the children in dataSnapshot
int totalChildren = (int) dataSnapshot.getChildrenCount();
if(totalChildren > 2)
//now check for this person properly
int milliSecInAWeek = 7*24*60*60*1000; //perhaps i m right ;)
//now check if the last of the three click was within this week
for(DataSnapshot snapshot : dataSnapshot.getChildren())
//well this is actully a loop kind of thing
//but we are just conserned about the first most click so we will call return just on the first child itteration :)
UserActivity userActivity = snapshot.getValue(UserActivity.class);
if(userActivity.getClickTime() - System.currentTimeMillis() < milliSecInAWeek)
//this person has clicked thrre times in this week disable the button buddy ;)
else
//this person has got chance(s) to click. let the button be enables :)
return;
else
//this user has clicked less then 3 times so the let the button be clickable for the user
else
//there is no activity by this user let the button be clickable
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
private class UserActivity
private float clickTime;
public UserActivity()
public UserActivity(float clickTime)
this.clickTime = clickTime;
public float getClickTime()
return clickTime;
public void setClickTime(float clickTime)
this.clickTime = clickTime;
hope it helps you and if does just accept the answer it ll help me a bit :)
happy coding !!!
answered Nov 14 '18 at 22:49
Har KalHar Kal
612414
612414
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
add a comment |
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
brill will look at this today @Har Kal
– markharrop
Nov 15 '18 at 9:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309519%2flimit-button-press-to-3-times-per-week%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
fetch data from server and track the time passed
– Har Kal
Nov 14 '18 at 22:18
my app is connected to firebase. how would you propose i get the time/date then track said time
– markharrop
Nov 14 '18 at 22:26
why are people marking this down?
– markharrop
Nov 15 '18 at 9:09
people are awesome ;) that's why they are down voting it...................lol
– Har Kal
Nov 15 '18 at 10:47
some people lol thanks for the help
– markharrop
Nov 15 '18 at 12:43