Tasarım dosyasına sadece bir text ekledim. Siz istediğiniz tasarımı yapın.
<TextView android:id="@+id/saat" android:layout_width="wrap_content" 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" />MainActivity.java dosyası; (sadece koyu renk olan yerleri ekledim.)
package com.example.okul.autorefresh1; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import android.widget.Toast; import java.sql.Time; import java.util.Calendar; public class MainActivity extends AppCompatActivity { private int saat; private int dakika; private int saniye; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); this.mHandler = new Handler(); this.mHandler.postDelayed(m_Runnable,5000); } private Handler mHandler; private final Runnable m_Runnable = new Runnable() { public void run() { TextView mesaj1=(TextView) findViewById(R.id.saat); Toast.makeText(MainActivity.this,"çalıştım",Toast.LENGTH_SHORT).show(); final Calendar c = Calendar.getInstance(); saat = c.get(Calendar.HOUR_OF_DAY); dakika = c.get(Calendar.MINUTE); saniye=c.get(Calendar.SECOND); mesaj1.setText(new StringBuilder().append(padding_str(saat)).append(":").append(padding_str(dakika)).append(":").append(padding_str(saniye))); MainActivity.this.mHandler.postDelayed(m_Runnable,20000); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } // tek basamak ve çift basamak durumu ayarı private static String padding_str(int c) { if (c >= 10) return String.valueOf(c); else return "0" + String.valueOf(c); } }