Comments (2)
Hi,
Thank you for your feedback. We verified this issue in the latest stable version of the Android Studio 3.5.3.
The solution, https://github.com/google-developer-training/android-kotlin-fundamentals-apps/tree/c67904408b9281d8e366ca3c4edacb8d4c552e36/ColorMyViews is working fine without any problems.
Closing this issue for now.
from android-kotlin-fundamentals-apps.
Hi,
Thank you for your feedback. We verified this issue in the latest stable version of the Android Studio 3.5.3.
The solution, https://github.com/google-developer-training/android-kotlin-fundamentals-apps/tree/c67904408b9281d8e366ca3c4edacb8d4c552e36/ColorMyViews is working fine without any problems.
Closing this issue for now.
That did not work for me. This is what I did :
package com.example.colormyviews
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Make a call to the setListeners function
setListeners()
}
/**
* Attaches listeners to all the views.
*/
private fun setListeners() {
// Get a reference for each TextView
val boxOneText = findViewById<TextView>(R.id.box_one_text)
val boxTwoText = findViewById<TextView>(R.id.box_two_text)
val boxThreeText = findViewById<TextView>(R.id.box_three_text)
val boxFourText = findViewById<TextView>(R.id.box_four_text)
val boxFiveText = findViewById<TextView>(R.id.box_five_text)
// Get a reference to Constraint Layout as defined in activity_main.xml
val rootConstraintLayout = findViewById<View>(R.id.constraint_layout)
// Get a reference to the buttons
val redButton = findViewById<Button>(R.id.red_button)
val greenButton = findViewById<Button>(R.id.green_button)
val yellowButton = findViewById<Button>(R.id.yellow_button)
// Make a list of views
val clickableViews: List<View> = listOf(boxOneText, boxTwoText, boxThreeText, boxFourText, boxFiveText, rootConstraintLayout, redButton, greenButton, yellowButton)
for (item in clickableViews) {
item.setOnClickListener { makeColored(it) }
}
}
/**
* Sets the background color of a view depending on it's resource id.
* This is a way of using one click handler to do similar operations on a
* group of views.
*/
private fun makeColored(view: View) {
when (view.id) {
// Boxes using Color class colors for the background
R.id.box_one_text -> view.setBackgroundColor(Color.DKGRAY)
R.id.box_two_text -> view.setBackgroundColor(Color.GRAY)
R.id.box_three_text -> view.setBackgroundColor(Color.BLUE)
R.id.box_four_text -> view.setBackgroundColor(Color.MAGENTA)
R.id.box_five_text -> view.setBackgroundColor(Color.BLUE)
// Boxes using custom colors for background
R.id.red_button -> box_three_text.setBackgroundResource(R.color.my_red)
R.id.yellow_button -> box_four_text.setBackgroundResource(R.color.my_yellow)
R.id.green_button -> box_five_text.setBackgroundResource(R.color.my_green)
// Set background color to light gray when background is touched
else -> view.setBackgroundColor(Color.LTGRAY)
}
}
}
I got an error saying Unresolved reference
for box_three_text, box_four_text, and box_five_text. Any help is apreciated.
from android-kotlin-fundamentals-apps.
Related Issues (20)
- Android Kotlin Fundamentals codelab: Repository pattern HOT 1
- Android Kotlin Fundamentals codelab: XML TitleFragment not found HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- step missing implementing the offline cache (entities, room, dao), Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: "Repository Pattern" Studio project is out of date / deprecated HOT 2
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: no se traduce al español. HOT 1
- Android Kotlin Fundamentals codelab: HOT 3
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
- Android Kotlin Fundamentals codelab: HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-kotlin-fundamentals-apps.