0

I created an activity to edit some data by clicking the edit button it will send the key of it to another activity. All of my activity works normally except this particular one that does not show anything other than blank screen.

These are my codes where the problem occured.

jadual_Activity_EditSlot_Pengajar.java

package com.example.karismatuitioncentre.jadual.j_pengajar;

import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.example.karismatuitioncentre.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;        

    public class Jadual_Activity_EditSlot_Pengajar extends AppCompatActivity {

EditText et_editSlot_subjek,et_editSlot_pengajar;
Button btn_editSlot_submit,btn_editSlot_back;
TextView tvTimeBeforeSet,tvTimeAfterSet,tvEditSlot_masaStart,tvEditSlot_masaEnd,tvSubjectSet,tvPengajarSet;
int t1Hour,t1Minute,t2Hour,t2Minute;


protected void OnCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hari_editslot_pengajar);
    String day_key=getIntent().getStringExtra("day_key");
    String slot_key=getIntent().getStringExtra("slot_key");

    tvSubjectSet= findViewById(R.id.tvSubjectSet);
    tvPengajarSet= findViewById(R.id.tvPengajarSet);
    tvTimeBeforeSet= findViewById(R.id.tvTimeBeforeSet);
    tvTimeAfterSet= findViewById(R.id.tvTimeAfterSet);
    et_editSlot_subjek= findViewById(R.id.et_editSlot_subjek);
    et_editSlot_pengajar= findViewById(R.id.et_editSlot_pengajar);
    tvEditSlot_masaStart= findViewById(R.id.tvEditSlot_masaStart);
    tvEditSlot_masaEnd= findViewById(R.id.tvEditSlot_masaEnd);
    btn_editSlot_submit= findViewById(R.id.btn_editSlot_submit);

    FirebaseDatabase.getInstance().getReference().child(day_key).child(slot_key).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            if (snapshot.exists()){
                String SubjectSet= Objects.requireNonNull(snapshot.child("subjek").getValue()).toString();
                String PengajarSet= Objects.requireNonNull(snapshot.child("pengajar").getValue()).toString();
                String HourBeforeSet= Objects.requireNonNull(snapshot.child("masaSHour").getValue()).toString();
                String MinuteBeforeSet= Objects.requireNonNull(snapshot.child("masaSMin").getValue()).toString();
                String HourAfterSet= Objects.requireNonNull(snapshot.child("masaEHour").getValue()).toString();
                String MinuteAfterSet= Objects.requireNonNull(snapshot.child("masaEMin").getValue()).toString();


                int startH=Integer.parseInt(HourBeforeSet);
                int startM=Integer.parseInt(MinuteBeforeSet);
                int endH=Integer.parseInt(HourAfterSet);
                int endM=Integer.parseInt(MinuteAfterSet);

                tvSubjectSet.setText(SubjectSet);
                tvPengajarSet.setText(PengajarSet);

                Calendar calendar = Calendar.getInstance();
                calendar.set(0,0,0,startH,startM);
                tvTimeBeforeSet.setText(DateFormat.format("hh:mm aa",calendar));

                Calendar calendar1 = Calendar.getInstance();
                calendar1.set(0,0,0,endH,endM);
                tvTimeAfterSet.setText(DateFormat.format("hh:mm aa",calendar1));
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });


    tvEditSlot_masaStart.setOnClickListener(view -> {
        TimePickerDialog timePickerDialog=new TimePickerDialog(
                Jadual_Activity_EditSlot_Pengajar.this,
                (view1, hourOfDay, minute) -> {
                    t1Hour=hourOfDay;
                    t1Minute=minute;

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(0,0,0,t1Hour,t1Minute);
                    tvEditSlot_masaStart.setText(DateFormat.format("hh:mm aa",calendar));


                },12,0,false
        );
        timePickerDialog.updateTime(t1Hour,t1Minute);

        timePickerDialog.show();
    });

    tvEditSlot_masaEnd.setOnClickListener(view -> {
        TimePickerDialog timePickerDialog=new TimePickerDialog(
                Jadual_Activity_EditSlot_Pengajar.this,
                (view1, hourOfDay, minute) -> {
                    t2Hour=hourOfDay;
                    t2Minute=minute;

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(0,0,0,t2Hour,t2Minute);
                    tvEditSlot_masaEnd.setText(DateFormat.format("hh:mm aa",calendar));

                },12,0,false
        );
        timePickerDialog.updateTime(t2Hour,t2Minute);

        timePickerDialog.show();
    });
    btn_editSlot_submit.setOnClickListener(view -> {

        Map<String,Object> map=new HashMap<>();
        map.put("subjek",et_editSlot_subjek.getText().toString());
        map.put("pengajar",et_editSlot_pengajar.getText().toString());
        map.put("masaSHour",t1Hour);
        map.put("masaEHour",t2Hour);
        map.put("masaSMin",t1Minute);
        map.put("masaEMin",t2Minute);


        FirebaseDatabase.getInstance().getReference().child(day_key).child(slot_key)
                .setValue(map)
                .addOnSuccessListener(aVoid -> {
                    et_editSlot_subjek.setText("");
                    et_editSlot_pengajar.setText("");

                    Toast.makeText(getApplicationContext(),"Penambahan berjaya",Toast.LENGTH_LONG).show();

                    Intent intent = new Intent(getApplicationContext(), Jadual_Activity_ViewSchedule_Pengajar_Test.class);
                    intent.putExtra("day_key", day_key);
                    startActivity(intent);
                    finish();
                })
                .addOnFailureListener(e -> Toast.makeText(getApplicationContext(),"Tidak Berjaya",Toast.LENGTH_LONG).show());

    });

}

}

activity_hari_editslot_pengajar.java

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat         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:orientation="vertical"
android:gravity="center"
android:background="@drawable/whitebg">
<TextView
    android:id="@+id/tvSubjectSet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20sp"
    android:text="TextView"
    android:textSize="20sp" />

<EditText
    android:id="@+id/et_editSlot_subjek"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20sp"
    android:layout_marginBottom="15dp"
    android:hint="Nama Subjek"
    android:inputType="text"
    android:textColor="#000"
    android:textColorHint="#95150D0D"
    android:textSize="20sp" />

<TextView
    android:id="@+id/tvPengajarSet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textSize="20sp" />

<EditText
    android:id="@+id/et_editSlot_pengajar"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20sp"
    android:layout_marginBottom="15dp"
    android:hint="Nama Pengajar"
    android:inputType="text"
    android:textColor="#000"
    android:textColorHint="#95150D0D"
    android:textSize="20sp" />

<TextView
    android:id="@+id/tvTimeBeforeSet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textSize="20sp" />

<TextView
    android:id="@+id/tvEditSlot_masaStart"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20sp"
    android:layout_marginBottom="15dp"
    android:background="#4BA8E697"
    android:drawablePadding="16dp"
    android:gravity="center"
    android:hint="Waktu Kelas Bermula"
    android:textColorHint="#95150D0D"
    android:textSize="20sp"
    android:textStyle="italic"
    app:drawableTopCompat="@drawable/ic_time" />

<TextView
    android:id="@+id/tvTimeAfterSet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:textSize="20sp" />

<TextView
    android:id="@+id/tvEditSlot_masaEnd"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20sp"
    android:layout_marginBottom="15dp"
    android:background="#68CDB1B0"
    android:drawablePadding="16dp"
    android:gravity="center"
    android:hint="Waktu Kelas Tamat"
    android:textColorHint="#95150D0D"
    android:textSize="20sp"
    android:textStyle="italic"
    app:drawableTopCompat="@drawable/ic_time" />

<Button
    android:id="@+id/btn_editSlot_submit"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="15dp"
    android:background="#1E88E5"
    android:text="Hantar"
    android:textColor="#F6F6F6"
    android:textSize="20sp" />

<Button
    android:id="@+id/btn_editSlot_back"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:background="#00ACC1"
    android:text="Kembali"
    android:textColor="#FFFFFF"
    android:textSize="20sp" />




</androidx.appcompat.widget.LinearLayoutCompat>
Ptr Zle
  • 1
  • 1
  • You are using `androidx.appcompat.widget.LinearLayoutCompat` try with only linear layout. – webaddicted Jun 08 '21 at 03:02
  • https://stackoverflow.com/questions/10022580/android-emulator-shows-nothing-except-black-screen-and-adb-devices-shows-device Try this solution. – Ken 262 Jun 08 '21 at 04:01
  • Thank you! I found out that I just referenced a different xml file for my layout after all. – Ptr Zle Jun 11 '21 at 08:51

0 Answers0