I hope to get an object of data calss with default value which from string resource file.
The code A will not be compiled because I have not to pass a Context
paramter for data class MVoice()
, I don't think it's a good way.
I there a simple way to get an object of data calss with default value which from string resource file in Kotlin?
Added Content:
If I use Code B, is it a good way ?
Code A
@Entity(tableName = "voice_table", indices = [Index("createdDate")])
data class MVoice(
@PrimaryKey @ColumnInfo(name = "id") var id: Long = 0,
var name: String = getString(R.String.Name)
)
<string name="Name">Untitled</string>
Code B
@Entity(tableName = "voice_table", indices = [Index("createdDate")])
data class MVoice(
@PrimaryKey @ColumnInfo(name = "id") var id: Long = 0,
var name: String
)
{
companion object {
fun getDefaultMVoice(mContext: Context): MVoice {
return MVoice(name = mContext.getString(R.string.name))
}
}
}