我在Udacity上制作了Android Kotlin教程,但是我的代码无法正常工作。请查看我的代码为什么不起作用。问题是SELECT `ringtunes`.*,
count(case when ringtune_history.Action = 'Download' then ringtune_history.Action end) as Org_Downloads,
count(case when ringtune_history.Action = 'View' then ringtune_history.Action end) as Org_Views,
count(case when ringtune_history.Action = 'Play' then ringtune_history.Action end) as Total_Plays,
count(case when ringtune_history.Action = 'Like' then ringtune_history.Action end) as Total_Likes,
`categories`.`Name` as `Category_Name`
FROM `ringtunes`
LEFT JOIN `ringtune_history` ON `ringtune_history`.`Ringtune_Id` = `ringtunes`.`Id`
LEFT JOIN `categories` ON `categories`.`Id` = `ringtunes`.`Category`
WHERE `ringtunes`.`Deleted` = 0
AND `ringtunes`.`Status` = 1
AND `categories`.`Deleted` = 0
AND `categories`.`Status` = 1
GROUP BY `ringtunes`.`Id`
ORDER BY `ringtunes`.`Id` DESC
LIMIT 20
没有运行。
这是我的MainActivity.kt
binding.doneButton.setOnClickListener
我在我的activity_main.xml中添加了package hu.webfeszek.aboutme
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
// import kotlinx.android.synthetic.main.activity_main.*
import hu.webfeszek.aboutme.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
setContentView(R.layout.activity_main)
binding.doneButton.setOnClickListener {
// This code does running never
Log.i("LOG_ME", binding.doneButton.text.toString())
addNickName(it)
}
}
private fun addNickName(view:View) {
}
}
,并在build.gradle中添加了3行:
<layout>
答案 0 :(得分:2)
请确保每次使用数据绑定进行更改时都重新构建项目,因为您需要为所做的每次更改生成代码。
如果您使用的是Android Studio,请进行项目重建。
还要删除setContentView(R.layout.activity_main)
,因为您正在使用数据绑定,所以不需要此行。
此外,您的xml按钮应如下所示:
<Button
android:text="Done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/done_button"
style="@style/Widget.AppCompat.Button.Colored"/>
您的Kotlin类onCreate:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.doneButton.setOnClickListener {
addNickname(view:View)
}