代码非常简单。headerView上有一个EditText,footerView上有一个EditText,使item的高度+headerView的高度+footerView的高度=屏幕的高度,点击HeaderView上的EditText后,再点击FooterView上的EditText,就会出现bug。任何人都可以帮我解释这个问题,我将非常感激,谢谢。
class MainActivity : AppCompatActivity() {
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val listView = findViewById<ListView>(R.id.listView)
listView.adapter = ArrayAdapter(this,
android.R.layout.simple_list_item_1,
arrayListOf("1", "2", "3", "4", "5", "6","1", "2", "3", "4", "5", "6"))
val headerView = LayoutInflater.from(this).inflate(R.layout.header, listView, false)
val etHeader = headerView.findViewById<EditText>(R.id.etComment)
listView.addHeaderView(headerView)
val footerView = LayoutInflater.from(this).inflate(R.layout.footer, listView, false)
val etFooter = footerView.findViewById<EditText>(R.id.etComment)
listView.addFooterView(footerView)
etHeader.setOnFocusChangeListener { v, hasFocus ->
Log.e("", "etHeader->setOnFocusChangeListener: $hasFocus")
}
etFooter.setOnFocusChangeListener { v, hasFocus ->
Log.e("", "etFooter->setOnFocusChangeListener: $hasFocus")
}
}
}
整个代码在这里:https ://github.com/tuchangwei/EditTextIssue 。