Sol Chikuse
asked on
How Do I reset Android Button Counter
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(savedInstan ceState);
setContentView(R.layout.co ntent_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.setOnClickListe ner(new View.OnClickListener() {
@Override
public void onClick(View v) {
String AnotherFunFact = mFactBook.getFunFact();
FunFact.setText(AnotherFun Fact);
PreviousFacts.add(AnotherF unFact);
ForwardIndexValue++;
}
});
BackButton.setOnClickListe ner(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ForwardIndexValue > 0){
ForwardIndexValue--;
String HistoryFunFact = PreviousFacts.get(ForwardI ndexValue) ;
FunFact.setText(HistoryFun Fact);
}
else {
FunFact.setText("Click Show Next Fun Fact to read more interesting facts about us");
}
}
});
}
}
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(savedInstan
setContentView(R.layout.co
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.setOnClickListe
@Override
public void onClick(View v) {
String AnotherFunFact = mFactBook.getFunFact();
FunFact.setText(AnotherFun
PreviousFacts.add(AnotherF
ForwardIndexValue++;
}
});
BackButton.setOnClickListe
@Override
public void onClick(View v) {
if (ForwardIndexValue > 0){
ForwardIndexValue--;
String HistoryFunFact = PreviousFacts.get(ForwardI
FunFact.setText(HistoryFun
}
else {
FunFact.setText("Click Show Next Fun Fact to read more interesting facts about us");
}
}
});
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This would solve the OP's problem.