如何解决Android:点击ListView FooterView上的EditText使键盘开闭,开闭
代码非常简单。 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","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,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。
解决方法
这是一个焦点抢占问题。添加以下代码。
etFooter.setOnFocusChangeListener { v,hasFocus ->
Log.e("","etFooter->setOnFocusChangeListener: $hasFocus")
if(hasFocus){
etFooter.setFocusable(true)
etFooter.setFocusableInTouchMode(true)
etFooter.requestFocus()
etFooter.findFocus()
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(etFooter,InputMethodManager.SHOW_FORCED);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。