我在数据库中有一个类型为double的列,现在,我得到了值并将其赋值给一个带符号的数字-数字十进制Edit Text,我使用kotlin toString方法将值转换为String。但是,编辑文本中未显示任何内容。当我使用println方法时,该值会出现在logcat中。我不知道该怎么办。我还有其他输入可以毫无问题地显示文本,但是这种编辑文本对我不起作用。
这是我用来开始活动的代码:
val recordEditButtonListener = View.OnClickListener {
val intent = Intent(context, AddEditRecordActivity::class.java)
intent.putExtra(RECORD_ID, currentRecord.id)
intent.putExtra(RECORD_CATEGORY, currentRecord.category)
intent.putExtra(RECORD_AMOUNT, currentRecord.amount)
intent.putExtra(RECORD_DATE, currentRecord.date)
intent.putExtra(RECORD_DESCRIPTION, currentRecord.description)
activity.startActivityForResult(intent, EDIT_RECORD_REQUEST)
}
这是来自活动本身:
val amountText = intent.getDoubleExtra(RECORD_AMOUNT, 1.0).toString()
amount_input.setText(amountText)
这是记录表的结构:
@Entity(
foreignKeys = [ForeignKey(
entity = Account::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("accountId"),
onDelete = CASCADE,
onUpdate = NO_ACTION
)]
)
class Record(
@PrimaryKey(autoGenerate = true) var id: Int?,
var amount: Double,
var category: String,
var description: String,
var date: String,
var recordImage: String,
var recordImageDescription: String,
var accountId: Int
)
这是xml:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/category_spinner"
android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent"
android:hint="@string/record_amount_input_text" android:id="@+id/amount_input"
android:inputType="numberSigned|numberDecimal"/>
<TextView
android:text="@string/record_select_date_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/date_text"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="@+id/amount_input"
android:layout_marginTop="32dp" app:layout_constraintTop_toBottomOf="@+id/amount_input"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/description_input" android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/date_text"
app:layout_constraintStart_toStartOf="@+id/date_text" android:inputType="text"
android:hint="@string/record_description_input_text"/>