Solved

How Do I reset Android Button Counter

Posted on 2016-10-02
2
37 Views
Last Modified: 2016-10-22
How do I reset the counter on a button in android studio.

My code is-----

public class MainActivity extends AppCompatActivity {

    private FactBook mFactBook = new FactBook();
    private ArrayList<String> PreviousFacts = new ArrayList<>();
    public int ForwardIndexValue = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        final TextView FunFact = (TextView) findViewById(R.id.funFact);
        final Button NextButton = (Button) findViewById(R.id.nextBtn);
        final Button BackButton = (Button) findViewById(R.id.backBtn);

        NextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String AnotherFunFact = mFactBook.getFunFact();
                FunFact.setText(AnotherFunFact);
                PreviousFacts.add(AnotherFunFact);
                ForwardIndexValue++;

            }
        });

        BackButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ForwardIndexValue > 0){
                    ForwardIndexValue--;
                    String HistoryFunFact = PreviousFacts.get(ForwardIndexValue);
                    FunFact.setText(HistoryFunFact);
                }
                else {
                    FunFact.setText("Click Show Next Fun Fact to read more interesting facts about us");

                }

            }

        });

    }
}
0
Comment
Question by:Sol Chikuse
  • 2
2 Comments
 
LVL 17

Accepted Solution

by:
Chris Harte earned 500 total points (awarded by participants)
ID: 41826187
Set it to zero inside the onCreate method. Every time it is created it will be set to zero

       super.onCreate(savedInstanceState);
       setContentView(R.layout.content_main);
       public int ForwardIndexValue = 0;

Open in new window

0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 41855075
This would solve the OP's problem.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Monitoring mobile application usage on iPhone 1 23
SD card might be causing Note 4 issues.  How can I fix? 103 167
Perplexed with Google Play 2 78
spam sms 9 39
Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
I tend toward trying the newest hardware and software.  Thiss sometimes works out to my benefit, and sometimes not.  Because I downloaded and installed Android 5.x (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.htm…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question