0

I have created a roundbutton. I want to display this roundbutton for the number in the count. The count represents the number of button presses. For example if the count equals 2 then 2 roundbutton must appear on the screen. Instead of me having to put each button on the screen and making it invisible at first then visible depending on the count.

roundbutton

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FF2A2A" />
<corners android:bottomRightRadius="10dp"
    android:bottomLeftRadius="10dp"
    android:topRightRadius="10dp"
    android:topLeftRadius="10dp"/>
</shape>
AnonymousZA
  • 121
  • 1
  • 11

2 Answers2

0

Make timer and change your image each second, but because that will be a timer...you need to change your image in runnable method, which will be behaving like UI thread.

Jevgenij Kononov
  • 1,210
  • 16
  • 11
  • @Jevgenjj Kononov is there a link as to show me how to achieve your above answer? – AnonymousZA Jun 19 '18 at 11:24
  • Try to look at this link: https://dzone.com/articles/how-schedule-task-run-interval 1. try create timer and ouput to logs time 2. inside that timer (where you updating your time) update your gui but update should be done with runnable method (Ui main thread) – Jevgenij Kononov Jun 19 '18 at 11:31
  • This link will be better: https://stackoverflow.com/questions/11730902/android-simple-time-counter – Jevgenij Kononov Jun 19 '18 at 11:32
  • Timer T=new Timer(); T.scheduleAtFixedRate(new TimerTask() { @Override public void run() { myTextView.setText("count="+count); count++; } }, 1000, 1000); – Jevgenij Kononov Jun 19 '18 at 11:33
  • Thanks for your help @Jevgenij Kononov – AnonymousZA Jun 19 '18 at 11:37
0

In your code, after count change you might change back by:

btnBack.setImageResource(R.drawable.ic_camera); 

also for change visibility you can use:

View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE)
Nikunj
  • 3,937
  • 19
  • 33
dariush
  • 216
  • 3
  • 10