Skip to content

Homework_Activity_3#222

Open
AnGuru-60 wants to merge 2 commits intoAndroid-Developer-Basic:homework/activity_03from
AnGuru-60:homework/activity_03
Open

Homework_Activity_3#222
AnGuru-60 wants to merge 2 commits intoAndroid-Developer-Basic:homework/activity_03from
AnGuru-60:homework/activity_03

Conversation

@AnGuru-60
Copy link

No description provided.

type = "image/*"
setPackage("org.telegram.messenger")

val imgUri = imageView.tag as? Uri

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Получаете uri, но не сохраняете его в tag. Из-за этого imgUri всегда будет null, и картинка не отправится в Telegram. Нужно добавить imageView.tag = uri в метод populateImage

findViewById<Button>(R.id.button)?.setOnClickListener {
val firstName = findViewById<EditText>(R.id.editFirstName).text.toString()
val lastName = findViewById<EditText>(R.id.editLastName).text.toString()
val age = findViewById<EditText>(R.id.editAge).text.toString().toInt()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может выбросить NumberFormatException
Используйте toIntOrNull() и обработайте случай, когда значение null

resultCode: Int,
intent: Intent?
): UserInfo? {
if (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можем упростить: if (resultCode != RESULT_OK || intent == null) return null

android:layout_marginTop="50dp"
android:ems="10"
android:hint="Возраст"
android:inputType="text"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для поля возраста лучше использовать number или numberSigned, чтобы пользователь мог вводить только числа

@AnGuru-60
Copy link
Author

@Lufavetskaya, большое спасибо за Ваши замечания!

  1. Необходимость imageView.tag = uri как-то упустил из виду, надо было под отладчиком внимательно посмотреть сформированный Intent для Telegram.

  2. val age = findViewById(R.id.editAge).text.toString().toInt() действительно выдаёт java.lang.NumberFormatException: For input string: "" при вводе пустого значения для возраста.

Сделал через оператор Элвиса: val age = findViewById(R.id.editAge).text.toString().toIntOrNull() ?: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants