Can I use a spinner in a fragment? I want to use a spinner in one of the fragment of my activity to set the time on my countdown timer. All the tutorials and videos I've seen uses activity and not fragment and i'm not sure if its the same way to make a spinner in a fragment.
package com.softeng.applockerproject;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
public class page2 extends Fragment {
private static final String TAG = "page2";
private Button btntest;
private TextView timer;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.page2_fragment,container,false);
btntest = (Button) view.findViewById(R.id.button2);
timer = (TextView) view.findViewById(R.id.Timer);
btntest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
countDownTimer.start();
}
});
return view;
}
//timer part
private CountDownTimer countDownTimer = new CountDownTimer(7200000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
long millis= millisUntilFinished;
String hms= String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis))
//TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
);
timer.setText(hms);
}
@Override
public void onFinish() {
Toast.makeText(getActivity(), "timer stopped",Toast.LENGTH_SHORT).show();
}
};
}