AutoCompleteTextView停止听onItemClick [英] AutoCompleteTextView stops listening to onItemClick

查看:123
本文介绍了AutoCompleteTextView停止听onItemClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现有code和XML 在code

  fromAutoComplete =新的自动完成(
        对此,R.layout.fromautocomplete,
        R.id.fromautocomplete);
fromAutoComplete.setNotifyOnChange(真正的);
fromAddress =(AutoCompleteTextView)findViewById(R.id.fromAddress);
fromAddress.setAdapter(fromAutoComplete);
fromAddress.setOnItemClickListener(本);
fromAddress.setOnFocusChangeListener(本);
fromAddress.setOnClickListener(本);
 

在XML

 < XML版本=1.0编码=UTF-8&GT?;
< TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / fromautocomplete
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ellipsize =无
    机器人:MAXLINES =2
    安卓的minlines =2
    机器人:单线=假
    机器人:文本=示例文本,大量的文字来鼓励文本换行/>
 

我需要自动完成包装的文字,对列表视图。所以我加了的LinearLayout在我的自动完成功能。这个工程。在自动完成列表视图现在已经换行的文本。 但是在我的回调选择非不叫

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>
<的TextView
    机器人:ID =@ + ID / fromautocomplete
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:MAXLINES =2
    安卓的minlines =2
    机器人:scrollHorizo​​ntally =假
    机器人:单线=假
    机器人:文本=示例文本,大量的文字来鼓励文本换行/>
 < / LinearLayout中>
 

解决方案

懂了工作,

修正

  1. 发表了 ID 我的的LinearLayout
  2. 使用的布局中的id 我的 onItemClick
  3. 使用 R.layout<文件> 在构造

XML(R.layout.fromautocomplete)

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / toautocompleteLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>

    <的TextView
        机器人:ID =@ + ID / toautocomplete
 

code

  fromAutoComplete =新的自动完成(这一点,
         R.layout.fromautocomplete,
                R.id.fromautocomplete);
        fromAutoComplete.setNotifyOnChange(真正的);
 

OnItemClick

  @覆盖
    公共无效onItemClick(适配器视图<>母公司视图中查看,INT位置,
            长ID){
        如果(view.getId()== R.id.fromautocompleteLayout){
 

Existing code and xml The code

fromAutoComplete = new AutoComplete(
        this, R.layout.fromautocomplete,
        R.id.fromautocomplete);
fromAutoComplete.setNotifyOnChange(true);
fromAddress = (AutoCompleteTextView) findViewById(R.id.fromAddress);
fromAddress.setAdapter(fromAutoComplete);
fromAddress.setOnItemClickListener(this);
fromAddress.setOnFocusChangeListener(this);
fromAddress.setOnClickListener(this);

The xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fromautocomplete"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="none"
    android:maxLines="2"
    android:minLines="2"
    android:singleLine="false"
    android:text="sample text, a lot of text to encourage wrap text"/>

I need the autocomplete to wrap text, on the listview. So I add a LinearLayout around my autocomplete. This works. The listview on the autocomplete now has wrapped text. but on selection non of my call backs are not called.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
<TextView 
    android:id="@+id/fromautocomplete"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:maxLines="2"
    android:minLines="2"
    android:scrollHorizontally="false"
    android:singleLine="false"
    android:text="sample text, a lot of text to encourage wrap text"/>
 </LinearLayout>

解决方案

Got it working,

Fixes

  1. Gave a id to my LinearLayout
  2. Used the layout id in my onItemClick
  3. Used R.layout.<file> in the constructor

XML (R.layout.fromautocomplete)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toautocompleteLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/toautocomplete"

Code

fromAutoComplete = new AutoComplete(this,
         R.layout.fromautocomplete,
                R.id.fromautocomplete);
        fromAutoComplete.setNotifyOnChange(true);

OnItemClick

@Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        if (view.getId() == R.id.fromautocompleteLayout) {

这篇关于AutoCompleteTextView停止听onItemClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆