I am having an issue in setting up my Chronometer. The Java file shows an error at "updateTimerText" stating Cannot resolve method "updateTimerText (java.lang.string) How do I solve this? Everything is Fine on the fragment I am trying to cast this task to it is just the Chronometer.java file. If you need any other information or code, let me know. Thanks in advance.
package com.example.platinumirish.runassistwithdrawer;
import android.content.Context;
import runassist.demo.fragments.MainFragment;
/**
* Created by Platinum Irish on 22/06/2016.
*/
public class Chronometer implements Runnable {
public static final long MILLIS_TO_MINUTES = 60000;
public static final long MILLIS_TO_HOURS = 3600000;
private Context mContext;
private long mStartTime;
private boolean mIsRunning;
public Chronometer(Context context){
mContext = context;
}
public void start() {
mStartTime = System.currentTimeMillis();
mIsRunning = true;
}
public void stop() {
mIsRunning = false;
}
@Override
public void run() {
while(mIsRunning) {
long since = System.currentTimeMillis() - mStartTime;
int seconds = (int) (since / 1000 % 60);
int minutes = (int)(((since / MILLIS_TO_MINUTES)) % 60);
int hours = (int)((since / (MILLIS_TO_HOURS)) % 24);
int millis = (int) since % 1000;
MainFragment mainFragment = (MainFragment) mContext.updateTimerText(String.format(
"%02d;%02d;%02d;%03d", hours, minutes, seconds, millis
));
}
}
}
Here is my Main Fragment too if it will help in any way, shape or form.
package runassist.demo.fragments;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.TextView;
import com.example.platinumirish.runassistwithdrawer.R;
public class MainFragment extends Fragment{
private TextView mTvTime;
private Button mBtnStart;
private Button mBtnStop;
private Context mContext;
private Chronometer mChronometer;
private Thread mThreadChrono;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
mTvTime = (TextView) rootView.findViewById(R.id.chronometer);
mBtnStart = (Button) rootView.findViewById(R.id.start_button);
mBtnStop = (Button) rootView.findViewById(R.id.stop_button);
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mChronometer == null) {
mChronometer = new Chronometer(mContext);
mThreadChrono = new Thread((Runnable) mChronometer);
mThreadChrono.start();
mChronometer.start();
}
}
});
mBtnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mChronometer !=null) {
mChronometer.stop();
mThreadChrono.interrupt();
mThreadChrono = null;
mChronometer = null;
}
}
});
return rootView;
}
public void updateTimerText(final String time) {
runOnUiThread(new Runnable() {
@Override
public void run () {
mTvTime.setText(time);
}
});
}
private void runOnUiThread(Runnable runnable) {
}
}