listview的edittext如何获得焦点

listview的多个edittext如何分别获得焦点呢?

//listview后获取焦点,优先级低于item

listView.setDescendantFocusability(ListView.FOCUS_AFTER_DESCENDANTS);

我的思路就是在edittext的头部包层button,监听button的点击事件,来获取焦点

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:orientation="horizontal"

android:paddingTop="10dp" >

<TextView

android:id="@+id/tv_faPiaoKaili"

style="@style/left_title"

android:text="@string/product_fapiaoKaili" />

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

<RadioGroup

android:id="@+id/radioGroup1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<RadioButton

android:id="@+id/radio0"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/product_fapiao3" />

<RadioButton

android:id="@+id/radio1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true"

android:text="@string/product_fapiao2" />

</RadioGroup>

<FrameLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<EditText

android:id="@+id/et_code"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/aboutus_content_bg003"

android:ems="10"

android:hint="@string/product_fapiaoCode"

android:inputType="phone"

android:padding="8dp" />

<Button

android:id="@+id/bt_code"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/transparent"

android:focusable="false"

/>

</FrameLayout>

<FrameLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<EditText

android:id="@+id/et_header"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="4dp"

android:background="@drawable/aboutus_content_bg003"

android:ems="10"

android:hint="@string/product_fapiaoHeader"

android:inputType="phone"

android:padding="8dp" />

<Button

android:id="@+id/bt_header"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/transparent"

android:focusable="false"

/>

</FrameLayout>

</LinearLayout>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:orientation="horizontal"

android:paddingTop="10dp" >

<TextView

android:id="@+id/tv_payMethod"

style="@style/left_title"

android:text="@string/product_payStyle" />

<Spinner

android:id="@+id/sp_payMethod"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@drawable/aboutus_content_bg003" />

</LinearLayout>

<TextView

android:id="@+id/tv_remark"

style="@style/left_title"

android:layout_marginTop="10dp"

android:text="@string/product_remark" />

<FrameLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<EditText

android:id="@+id/et_remark"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/aboutus_content_bg003"

android:ems="115"

android:gravity="left"

android:minHeight="80dp"

android:padding="5dp" />

<Button

android:id="@+id/bt_remark"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/transparent"

android:focusable="false"

/>

</FrameLayout>

//代码

viewHolder004.bt_code.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

//其它两个edittext先设置不能获取焦点

viewHolder004.et_header.setFocusable(false);

viewHolder004.et_remark.setFocusable(false);

showSoftInput(viewHolder004.et_code);

}

});

viewHolder004.bt_header.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

viewHolder004.et_code.setFocusable(false);

viewHolder004.et_remark.setFocusable(false);

showSoftInput(viewHolder004.et_header);

}

});

viewHolder004.bt_remark.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

viewHolder004.et_header.setFocusable(false);

viewHolder004.et_code.setFocusable(false);

showSoftInput(viewHolder004.et_remark);

}

});

/**

* @param editText  系统键盘的弹出

*/

private void showSoftInput(EditText editText) {

//3个一起设置才有效,不然可能无效

editText.setFocusable(true);

editText.setFocusableInTouchMode(true);

editText.requestFocus();

InputMethodManager inputMethodManager=(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

//系统键盘显示后=>隐藏的切换

//inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, //InputMethodManager.HIDE_NOT_ALWAYS);

//没用

//inputMethodManager.showSoftInputFromInputMethod(viewHolder004.et_code.getWindowToken(), //InputMethodManager.SHOW_IMPLICIT);

//显示系统键盘

inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

}

listview的edittext如何获得焦点

时间: 2024-08-10 23:11:15

listview的edittext如何获得焦点的相关文章

【转】Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法

Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法 [原文链接] 这篇文章完美的解决了我几个月没结论的bug... 感谢热爱分享的技术达人~ 我是怎么走进这个大坑的..... 需求: 在listview中出一个EditText 接受用户输入消息. 前期解决方案: 给这个EditText绑定焦点事件.... 悲剧就开始了... 知道吗?当这个EditTextView被点了下,它的焦点就不断的获取,失去,获取,失去...  只点一下... 就频繁的重复..最后大部

关于ListView中EditText在软键盘弹出后的焦点问题

转自:http://www.cnblogs.com/haofei/p/3305030.html 在ListView中,每次弹出软键盘后就会重新调用getView()方法,导致EditText失去焦点. 解决办法:在getView()方法中添加监听器: editText.setOnTouchListener(new OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEve

Android启动Activity之后阻止EditText自动获得焦点

这个问题是StackOverFlow上面一个热门的问题Stop EditText from gaining focus at Activity startup.现在我将这个问题翻译并且将各路答案进行整理,保证可以解决这个问题 作者遇到的问题如下: 我有一个Activity,里面有一个EditText和一个ListView,每当我启动Activity的时候,EditText都会自动获取焦点(光标在那里一闪一闪的).而我不希望他自己获得焦点,我尝试了如下语句 EditText.setSelected

【Android】ListView中EditText焦点问题

一.描述: 近期一个项目中需要开发一种类似表格的界面来显示和配置参数,Android并无直接类似表格的控件支持,我采用了ListView中布局EditText和TextView来实现,其中TextView用来显示参数表示符,EditText用来显示参数值,用一个自定义AlertDialog弹出显示,如下图所示. 二.问题: 开发出来的APK软件,在手机上操控是OK的,但在电视上无法操控,具体表现为: 三.解决: 1  通过设置focus停在ListView上,解决ListView无法点击的问题.

android ListView与EditText共存错位

在一个ListView中,如果里面有EditText会很麻烦,因为修改EditText里面的数据会发生错位现象. 这时候,需要在适配器BaseAdapter的getView中设置setTag(),将position缓存起来. 下面来解决这个问题. 1.打开activity_main.xml . <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="htt

Android 如何使edittext默认失去焦点

1.在布局文件中给edittext的父控件增加两个属性 android:focusable="true" android:focusableInTouchMode="true" 2.直接调用edittext的clearFocus()方法,不过该方法有时候会不生效 searchView.setFocusable(true); searchView.setFocusableInTouchMode(true); searchView.requestFocus(); sea

edittext设置获得焦点时的边框颜色

第一步:为了更好的比较,准备两个一模一样的EditText(当Activity启动时,焦点会在第一个EditText上,如果你不希望这样只需要写一个高度和宽带为0的EditText即可避免,这里就不这么做了),代码如下: view plain <EditText android:layout_width="fill_parent" android:layout_height="36dip" android:background="@drawable/

Edittext默认无焦点

开发中,发现第一次进入页面时光标就会出现在页面的第一个edittext中,解决思路是: 在edittext的父布局中加入两行代码夺取焦点 <com.zhy.autolayout.AutoLinearLayout android:layout_width="match_parent" android:layout_height="50px" android:background="@android:color/white" android:o

Android EditText 获取到焦点

1.第一种方式  这种方式点击输入框不能打开软键盘,点击第二次才可以打开 失去焦点 editText.setFocusable(false); 获取焦点 editText.setFocusable(ture); editText.setFocusableInTouchMode(true); editText.requestFocus(); 2.第一种方式 失去焦点 editText.clearFocus(); 获取焦点 editText.requestFocus(); 版权声明:本文为博主原创文