然后editext获得焦点

然后editext获得焦点

本文介绍了单击gridview项,然后editext获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经显示了一个gridview,其项目为textview和edittext.现在,如何实现单击gridview项目并使edittext获得焦点的功能?

I have displayed a gridview whose items are a textview and edittext.Now ,how to achieve function that I click the gridview item and the edittext get the focus?

gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

如何覆盖此功能?我之前尝试过:

how to override this function?I try that before:

((EditText)gridview.getChildAt(position).findViewById(R.id.grid_edittext)).requestFocus();

还有:

((ViewGroup)gridview.getChildAt(position)).getChildAt(1).requestFocus();

其中添加了一个System.out.printlen("hello");在onitemclick函数中,但没有显示在logcat中.

There adds a System.out.printlen("hello");in onitemclick function,but it doesn't show up in logcat.

有样品吗?

推荐答案

AdapterView 获取 EditText 并按如下所示设置 requestFocus().这可能是可行的.

Get EditText from AdapterView and set requestFocus() as below. This may be work.

gridView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
            EditText edittext = (EditText) view.findViewById(R.id.grid_edittext);
            edt.setFocusable(true);
            edittext.setFocusableInTouchMode(true);
            if (edittext.requestFocus()) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(edittext, InputMethodManager.SHOW_IMPLICIT);
            }
      }
   });

EditText focusable focusableInTouchMode 设置为 false ,如下所示:

Set focusable and focusableInTouchMode to false for EditText as below:

android:focusable="false"
android:focusableInTouchMode="false"

这篇关于单击gridview项,然后editext获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:39