Question

I am trying to update a TextView after clicking a button. I am also appending to the String a value that is giving me from another function. For some reason, when I try to do this it doesn't update, however it works perfectly when it is just a regular String without the function.

Here is my onClick code:

 enterButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                MonitorObserver.updateWalk(context); 
                analyse = new WalkingAnalyse(context);
                analyse.enterActivity(Float.parseFloat(timeString), Float.parseFloat(distanceString), 0); //this is what to do whenever inserting a new activity
                recommendationTextView.setText("Recommendation: "+recommend.recommend(context)+" meters"); //it works without the recommend.recommend(context) function

        }
    });

    public String recommend(Context context){
       return Float.toString(currentRecommendation);
    }

I should probably also add the TextView is updated whenever I leave the screen and then return to it.

Any ideas?

Thanks in advance!

Was it helpful?

Solution

Maybe you should Set the text before entering the new activity?

recommendationTextView.setText("Recommendation: "+recommend.recommend(context)+" meters");
MonitorObserver.updateWalk(context); 
analyse = new WalkingAnalyse(context);
analyse.enterActivity(Float.parseFloat(timeString), Float.parseFloat(distanceString), 0); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top