Я делаю код, чтобы добавить оставшиеся дни, но он показывает, что некоторые из моих кодов являются ошибкой, и я новичок в Android Studio.
Я также загружаю ошибку logcat, пожалуйста, нажмите здесь :
[AddRemainDaysActivity.java]
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class AddRemainDaysActivity extends AppCompatActivity {
TextView textviewAsgName;
EditText editTextRemaindDays;
Button buttonAdd;
ListView listViewRemainDays;
DatabaseReference databaseRemainDays;
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.add_remain_days);
textviewAsgName = (TextView) findViewById(R.id.textViewAsgName);
editTextRemaindDays = (EditText) findViewById(R.id.editTextRemaindDays);
buttonAdd = (Button) findViewById(R.id.buttonAdd);
listViewRemainDays = (ListView) findViewById(R.id.listViewRemainDays);
Intent intent = getIntent();
String id = intent.getStringExtra(MainActivity.ASSIGNMENT_ID);
String topic = intent.getStringExtra(MainActivity.ASSIGNMENT_TOPIC);
textviewAsgName.setText(topic);
databaseRemainDays = FirebaseDatabase.getInstance().getReference("remainDays").child(id);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
saveremainDays();
}
});
}
private void saveremainDays(){
String remainDaysname = editTextRemaindDays.getText().toString().trim();
if(!TextUtils.isEmpty(remainDaysname)) {
String id = databaseRemainDays.push().getKey();
remainDays RemainDays = new remainDays(id, remainDaysname);
databaseRemainDays.child(id).setValue(RemainDays);
Toast.makeText(this,"Remain days added :)", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(this, "You must insert remaining days to proceed!", Toast.LENGTH_LONG).show();
}
}
}````
[stayDays.java]
пакет com.example. as3;
publi c class stayDays {
private String remainDaysID;
private String remainDaysname;
public remainDays() {
}
public remainDays(String remainDaysID, String remainDaysname) {
this.remainDaysID = remainDaysID;
this.remainDaysname = remainDaysname;
}
public String getRemainDaysID() {
return remainDaysID;
}
public String getRemainDaysname() {
return remainDaysname;
}
} `` ``
Это файл XML:
[add_remain_days_xml]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/Activity_add_remaindays"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AddRemainDaysActivity">
<TextView
android:id="@+id/textViewAsgName"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<EditText
android:id="@+id/editTextRemainDays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter remaining days"
android:inputType="textPersonName"
android:layout_marginTop="20dp"/>
<Button
android:id="@+id/buttonAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:text="Add" />
<TextView
android:id="@+id/textView"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Assignment"/>
<ListView
android:id="@+id/listViewRemainDays"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>````