Laboratorio:13: Android Studio Docentes: Paz Purisaca Rolando
Laboratorio:13: Android Studio Docentes: Paz Purisaca Rolando
Actividad 1:
Mostrar la fecha del sistema
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#03A9F4"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000"
tools:layout_editor_absoluteX="104dp"
tools:layout_editor_absoluteY="71dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv1"
android:onClick="calcular"
android:text="Ver Fecha" />
</RelativeLayout>
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Actividad 2:
Mostrar la hora del sistema
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"
android:background="#FFC107"
tools:context=".MainActivity2">
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv2"
android:onClick="calcularH"
android:text="Ver Hora" />
</RelativeLayout>
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Actividad 3:
Mostrar el nombre del mes
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#C1ED8E"
tools:context=".MainActivity3">
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv3"
android:onClick="calcularM"
android:text="Button" />
</RelativeLayout>
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Actividad 4:
Mostrar un calendario y seleccionar un día.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#FAE6FD"
tools:context=".MainActivity4">
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />
<CalendarView
android:id="@+id/cal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv4"
android:background="#FFFAD1" />
</RelativeLayout>
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class MainActivity4 extends AppCompatActivity {
public TextView tv4;
public CalendarView cal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
tv4=(TextView) findViewById(R.id.tv4);
cal=(CalendarView) findViewById(R.id.cal);
cal.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
{
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth)
month=month+1;
tv4.setText("Fecha seleccionada: "+dayOfMonth+"/"+month+"/"+year);
}
});
}
}