我想定义一个由一些属性组成的类,稍后将在程序中使用。 对于本课程,我将需要一个方法,函数来对此卡进行调头。 我偶然发现了允许我访问可绘制
中的png图像的字符串如何在以下位置访问iflagimage值: “ imageView.setImageResource(R.drawable.iflagimage())”
我的解决方案不起作用... 稍后将在RecyclerView中单击FlagCard(iflagCard)来调用此功能! 并应旋转此flagCard:-)
如果有比我感兴趣的伴侣对象更简单的东西,那么我是新手... 并且IDE不接受flagCard:-(
package training.geography.triplerecyclerview
import android.os.Bundle
import android.view.animation.Animation
import android.view.animation.RotateAnimation
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
data class FlagCard(var flagtrigramup: String, var flagtrigramdown: String,
val flagimage: String, var flagsouth: String, var rotationpossible: Boolean=(true)) {
companion object {
fun createiflagCard(flagtrigramup: String, flagtrigramdown: String,
flagimage: String,flagsouth: String,rotationpossible: Boolean)= flagCard
}
fun rotateflagcard(flagCard: FlagCard) {
// if (rotationpossible) { Quand la fonction sera appelée
var iflagcard = FlagCard
var iflagtrigramup = flagtrigramup
var iflagtrigramdown = flagtrigramdown
var iflagimage = flagimage
var iflagsouth = flagsouth
var imageView = ImageView(this)
imageView.setImageResource(R.drawable.iflagimage())
imageView.setOnClickListener {
imageView.animate().apply {
rotationBy(180f)
duration = 1000L
start()
var flagtemp: String = iflagtrigramup
iflagtrigramup = iflagsouth
iflagtrigramdown = flagtemp
}
//} else {
//Toast.makeText(this, "flag already matched country", Toast.LENGTH_LONG).show()
//}
}
}
}