Не меняется текст в TextView
Столкнулся с проблемой того, что текст TextView не меняется, хотя вроде бы должен (похоже, что не должен, раз не меняется). В общем, имеется такой кусок кода:
package com.example.beecalc;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class open extends AppCompatActivity {
String name;
DBHelper db;
String s_date;
Integer[] date = {7,10,14,16,23,26,28};
Cursor cr;
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.open);
name = getIntent().getStringExtra("name");
db = new DBHelper(this);
SQLiteDatabase sql = db.getWritableDatabase();
cr = sql.query(DBHelper.TABLE, new String[]{DBHelper.KEY_DATE}, "name = '" + name + "'",
null, null, null, null);
cr.moveToFirst();
s_date = cr.getString(cr.getColumnIndex(DBHelper.KEY_DATE));
cr.close();
TextView n = findViewById(R.id.textView2);
n.setText(name);
final TextView d = findViewById(R.id.textView5);
d.setText(s_date);
TextView[] s = {
findViewById(R.id.textView14),
findViewById(R.id.textView16),
findViewById(R.id.textView18),
findViewById(R.id.textView23),
findViewById(R.id.textView20),
findViewById(R.id.textView22),
findViewById(R.id.textView11)
};
for (int i = 0; i == 6; i++) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDate localDate = LocalDate.parse(s_date, formatter);
LocalDate incrementedDate = localDate.plusDays(date[i]);
s[i].setText("test"+i);
}
}
public void delete(View view) {
AlertDialog.Builder dlg = new AlertDialog.Builder(open.this);
dlg.setMessage("Вы уверены, что хотите удалить запись?")
.setNegativeButton("Отмена", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast t = Toast.makeText(open.this, "Действие отменено", Toast.LENGTH_LONG);
t.show();
}
})
.setPositiveButton("Удалить", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SQLiteDatabase s = db.getWritableDatabase();
s.delete(DBHelper.TABLE, "name = '"+name+"'", null);
Toast.makeText(open.this, "Запись успешно удалена.", Toast.LENGTH_SHORT).show();
Intent i = new Intent(open.this, MainActivity.class);
startActivity(i);
finish();
}
})
.create();
dlg.show();
}
protected void onDestroy() {
super.onDestroy();
Intent i = new Intent(open.this, MainActivity.class);
startActivity(i);
finish();
}
}
Кусок расположен внутри метода "onCreate", "date" - массив типа int, "s_date" - переменная в формате String, содержащая в себе дату. В логах нет данных об ошибке.
Разметка:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".open">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="229dp"
android:layout_height="wrap_content"
android:text="Название записи: "
android:textSize="18sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ДАТЫ"
android:textAlignment="center"
android:textAllCaps="true"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView4"
android:layout_width="227dp"
android:layout_height="wrap_content"
android:text="Дата закладки:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView13"
android:layout_width="206dp"
android:layout_height="wrap_content"
android:text="Формирование отводков:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView15"
android:layout_width="258dp"
android:layout_height="wrap_content"
android:text="Запечатывание маточников:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView17"
android:layout_width="139dp"
android:layout_height="wrap_content"
android:text="Выдача маточников в отводки:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView100"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Выход матки:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView19"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Облет маток:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView21"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Осеменение:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView10"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Проверка яйцекладки:"
android:textSize="18sp" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ошибка"
android:textSize="18sp" />
</TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="200sp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/del"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Удалить запись"
android:textSize="20sp"
android:onClick="delete"
/>
</TableRow>
</TableLayout>
Помогите, пожалуйста, разобраться в чем дело. Спасибо!