• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Newbie need some help

Hello, I am completely new to coding
and have been trying to make a drug dosage calculator
the idea of the app is that there is a Seekbar on top for user to adjust the body weight
so that all the drug will spontaneously show the calculated dosage.

I have a successful attempt when making the first trial using one MainActivity and one XML file (referring to the pic success_trial.jpg)


However, when I do my second attempt to make a Tab Layout with Swipeable Views, the app force closed once I touch the Seekbar.(referring to the pic failed_trial.png)

I have been following this tutorial from androidhive.(http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/)

Should those code for calculation and display done in the MainActivity class or in the fragment class?
I guess my main problem is that I don't know how to setText to or findViewById from another class. Any help is appreciated.
 

Attachments

  • failed_trial.png
    failed_trial.png
    274.2 KB · Views: 133
  • success_trial.jpg
    success_trial.jpg
    50.1 KB · Views: 103
You say the app closed. There must be some output in your logcat view. Post that and someone may be able to help you.
 
ok I see you got some help on that one. Are there any specific problems you are still struggling with?
 
You could do that with a setter method on the fragment class

Code:
class AntimicrobialFragment {
  private double bodyWeight
  ..

  public void setBodyWeight(double bodyWeight) {
    this.bodyWeight = bodyWeight;
  }

So in your MainActivity class you would create a new instance of the AntimicrobialFragment class, and call the setter method

Code:
class MainActivity extends AppCompatActivity {
  private AntimicrobialFragment fragment;

  ...

  fragment.setBodyWeight(trueBW);

  ...
}

BTW you should mark that answer on SO as accepted, the guy took the time to answer your question, so give him the rep points.
 
Back
Top Bottom