Skip to content

Hyooosong/step.01#6

Closed
hyooosong wants to merge 4 commits into
Step.01-Solution-Databinding-Start_use_local_valuefrom
hyooosong/Step.01
Closed

Hyooosong/step.01#6
hyooosong wants to merge 4 commits into
Step.01-Solution-Databinding-Start_use_local_valuefrom
hyooosong/Step.01

Conversation

@hyooosong
Copy link
Copy Markdown
Member

Step.01 dataBinding local_value ์‹ค์Šต

@hyooosong hyooosong self-assigned this Dec 31, 2020
@hyooosong hyooosong added the ํšจ์†ก ๋‹ด์žฅ์ž: ํšจ์†ก label Dec 31, 2020
hyooosong added a commit that referenced this pull request Dec 31, 2020
hyooosong added a commit that referenced this pull request Jan 1, 2021
Copy link
Copy Markdown
Member

@jinsu4755 jinsu4755 left a comment

Choose a reason for hiding this comment

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

๋„ˆ๋ฌด๋„ˆ๋ฌด ์ˆ˜๊ณ ํ–ˆ์–ด~ ํ•˜์ง€๋งŒ invalidateAll ์ด๋ผ๋Š” ์นœ๊ตฌ๋Š” ์กฐ๊ธˆ ๋” ์ฐพ์•„๋ณด๊ณ  ์•Œ์•„๋ณด๊ณ  ๊ณ ์น  ์ˆ˜ ์žˆ์Œ ๊ณ ์ณ๋ณด์ž!

Comment thread app/build.gradle Outdated
Comment on lines +34 to +35
dataBinding {
enabled = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#5 (comment)

์ฐธ๊ณ ํ•ด๋ณด์ž!

import sotp.semina.practicegitanddatabinding.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#5 (comment)

์ด๊ฑฐ ์ฐธ๊ณ ํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„!


class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
var profilename = "profileName"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

์ผ๋‹จ ๋ณ€์ˆ˜ ์ด๋ฆ„ ๊ทœ์น™์— ๋”ฐ๋ผ profileName ์ด๋ผ๊ณ  ์ ์–ด์ฃผ๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„!

๋งŒ์•ฝ ๋ถˆํ•„์š”ํ•œ ๋ณ€์ˆ˜๋ผ๋ฉด ์ง€์›Œ์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์•„

์‹ฌ์ง€์–ด ๊ทธ๊ฒŒ val๋„ ์•„๋‹ˆ๊ณ  var์ด๋ผ๋ฉด ํ•ด๋‹น ํ”„๋กœํผํ‹ฐ๋Š” ์ž๋ฐ”์—์„œ ๋งด๋ฒ„๋ณ€์ˆ˜,getter,setter์ธ๋ฐ ๋ณ€์ˆ˜ ํ•˜๋‚˜ ์ž˜๋ชป ๋„ฃ์–ด๋‘๋ฉด ๋ถˆํ•„์š”ํ•œ ์ฝ”๋“œ๋ฅผ ๋ฌด๋ ค 3๊ฐ€์ง€๋‚˜ ๋งŒ๋“ค๊ฒŒ ๋˜๋ฏ€๋กœ ๋‚˜๋Š” ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง„ ์•Š์•„...

profileName.text = content
private fun setProfileName(content:String) {
profilename = content
binding.invalidateAll()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

์•ต? ๋‚œ ์ด ์นœ๊ตฌ๋ฅผ LiveData๋งŒ ์จ์„œ ์ฒ˜์Œ๋ณด๊ณ  ์•Œ์•„๋ดค๋Š”๋ฐ ํ ...ํผํฌ๋จผ์Šค์ ์œผ๋กœ ์•„์ฃผ ์•ˆ ์ข‹์€๊ฑฐ ๊ฐ™์•„.

Invalidates all binding expressions and requests a new rebind to refresh UI. ๋ผ๋Š”๋ฐ
UI๋ฅผ ๊ณ ์น˜๊ธฐ ์œ„ํ•ด ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๊ฒฐํ•ฉ์‹์„ ๋ฌด์‹œํ•˜๊ณ  ๋‹ค์‹œ ๋ฐ”์ธ๋”ฉํ•œ๋‹ค๋Š” notifyDataSetChanged ๋ณด๋‹ค ๋” ํ•œ ๊ธฐ๋ถ„์ธ๊ฑธ..? ๋ทฐ๊ฐ€ ๊ฐ„๋‹จํ•  ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ๋ทฐ๊ฐ€ ๋ณต์žกํ•˜๋‹ค๋ฉด ํ•ด๋‹น ํ•จ์ˆ˜์˜ ์‚ฌ์šฉ์€ ํ™”๋ฉด ๊นœ๋นก์ž„์ด ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋‹ค ์ƒ๊ฐํ•ด.

๊ทธ๋ƒฅ ํ•ด๋‹น ํ…์ŠคํŠธ ๋ทฐ์— text๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ๋˜๋Š”๊ฑธ
textView .text์˜ ๋ณ€๊ฒฝ์„ ์œ„ํ•ด์„œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ์—ฐ๊ฒฐํ•œ๋‹ค..? ์•„์ฃผ ๋น„ํšจ์œจ์ ์ด๋ผ ์ƒ๊ฐํ•ด

binding.textProfileName,
getEditTextToString(binding.inputChangedProfile)
)
setProfileName(getEditTextToString(findViewById(R.id.input_changed_profile)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

์ด ๋ถ€๋ถ„์€ dataBinding์„ ์‚ฌ์šฉํ•จ์—๋„ findViewById๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์žˆ๋„ค!

dataBinding์ด ์ด๋Ÿฌํ•œ ๊ธ€๋ฃจ์ฝ”๋“œ๋ฅผ ์‚ฌ๋ผ์ง€๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ธ๊ฑธ?

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_profile_image"
tools:text="profile name" />
tools:text="@{mainActivity.profilename}" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

์œ„์˜ ๋ฆฌ๋ทฐ๋“ค๊ณผ ์ด์–ด๋ณด๋ฉด ์•„๋งˆ ์ด ๋ถ€๋ถ„์ด ์ด๋ ‡๊ฒŒ ๋  ํ•„์š”๊ฐ€ ์—†์—ˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์„ ๊ฑฐ์•ผ!

๋ญ”๊ฐ€ ์ฝ”๋“œ๊ฐ€ ๋งˆ์น˜ ํ•ด๋‹น profileName์ด LiveData์ด๋ฉฐ Activity๋ฅผ ViewModel์ฒ˜๋Ÿผ ์—ฐ๊ฒฐํ–ˆ๋Š”๋ฐ ๋‘˜ ๋‹ค ์‚ฌ์šฉ์ค‘์ด์ง€ ์•Š์œผ๋ฏ€๋กœ ๊ตณ์ด? ์ด๋Ÿด ํ•„์š”๋Š” ์—†์„ ๊ฑฐ ๊ฐ™์•„

๋‹ค๋งŒ ๋ณด๋‹ค ์™„๋ฒฝํ•œ DataBinding์„ ์œ„ํ•ด์„œ LiveData, ViewModel๋ฅผ ์จ์ค€๋‹ค๋ฉด ์ด๋ ‡๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ๋งž์•„!

@jinsu4755 jinsu4755 added the wontfix This will not be worked on label Jan 1, 2021
build.gradle ์ˆ˜์ •, invalidateAll() ์ œ๊ฑฐ, ๊ธ€๋ฃจ์ฝ”๋“œ ์ œ๊ฑฐ, binding ์ „์—ญ๋ณ€์ˆ˜ ์ˆ˜์ •

Related to : #2, #6
์ถ”๊ฐ€ ๋ณ€์ˆ˜ ์ˆ˜์ •

Related to : #2, #6
Copy link
Copy Markdown
Member

@jinsu4755 jinsu4755 left a comment

Choose a reason for hiding this comment

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

๋”ฐ๋ฒ™

@jinsu4755 jinsu4755 added Good ๊ณผ์ œ ์™„๋ฃŒ and removed wontfix This will not be worked on labels Jan 1, 2021
@hyooosong hyooosong closed this Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good ๊ณผ์ œ ์™„๋ฃŒ ํšจ์†ก ๋‹ด์žฅ์ž: ํšจ์†ก

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants