天啊,我有一个带适配器的ListView,当应用程序启动代码时,在我单击EditText后将EditText放入我的ListView中我无法写入所以我试图解决这个问题我做了一个焦点,它的工作正常并且应用程序允许我写,但写完后,我隐藏键盘文本将消失。
当我点击进入时,我想这个editText通常和任何其他EditText一样,当我点击完成时,键盘消失,我的文字就在那里。我该怎么做?
var List=ArrayList<Ticket>()
var adapter:ListAdabter?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_act2)
List.add(Ticket("1"))
adapter=ListAdabter(this,List)
listview.adapter=adapter
}
fun View.showKeyboard() {
this.requestFocus()
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}
inner class ListAdabter :BaseAdapter{
var ListLocal = ArrayList<Ticket>()
var mCtx:Context?=null
constructor(mCtx:Context,List:ArrayList<Ticket>):super(){
this.ListLocal=List
this.mCtx=mCtx
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val item = ListLocal[position]
val layoutInf = LayoutInflater.from(mCtx)
val view = layoutInf.inflate(R.layout.add_ticket,null)
val edit = view.findViewById<EditText>(R.id.txtDes)
edit.requestFocus()
edit.showKeyboard() //The Problem is Here
return view
}
override fun getItem(position: Int): Any {
return ListLocal[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
return ListLocal.size
}
}