Created
November 27, 2019 19:33
-
-
Save CodeNextPaco/e155274b1023de0d3a1b30dab484bb9e to your computer and use it in GitHub Desktop.
ProgressBar + CountDownTimer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:id="@+id/cdText" | |
android:layout_height="wrap_content" | |
android:text="Hello World!" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<ProgressBar | |
android:id="@+id/progressBar" | |
style="?android:attr/progressBarStyleHorizontal" | |
android:layout_width="285dp" | |
android:layout_height="48dp" | |
android:layout_marginTop="52dp" | |
android:max="100" | |
android:progress="40" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/cdText" | |
app:layout_constraintVertical_bias="0.110000014" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.os.CountDownTimer; | |
import android.widget.ProgressBar; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private TextView displayText; | |
private ProgressBar progBar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
displayText = findViewById(R.id.cdText); | |
progBar = findViewById(R.id.progressBar); | |
long msFuture = 30000; | |
progBar.setMax((int)msFuture); | |
new CountDownTimer(msFuture, 1000) { | |
public void onTick(long msUntilFinished) { | |
displayText.setText("remaining sec: " + msUntilFinished / 1000); | |
progBar.setProgress((int)msUntilFinished); | |
} | |
public void onFinish() { | |
displayText.setText("done!"); | |
} | |
}.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment