Android 微调器,单击外部后自动完成文本视图填充(错误?)
我使用的是一个Android 微调器,单击外部后自动完成文本视图填充(错误?),android,Android,我使用的是一个AutoCompleteTextView(微调器下拉列表也是如此)。填充时,下拉列表中的项目具有适当的填充。下面是它的外观: 但是如果我没有从下拉列表中选择任何内容并单击“外部”(现在下拉列表已隐藏),然后再次单击AutoCompleteTextView/微调器,则显示的下拉列表没有应有的填充。左边的填充物不见了 我将适配器用作: ArrayAdapter<String> adapter = new ArrayAdapter<String>(contex
AutoCompleteTextView
(微调器下拉列表也是如此)。填充时,下拉列表中的项目具有适当的填充。下面是它的外观:
但是如果我没有从下拉列表中选择任何内容并单击“外部”(现在下拉列表已隐藏),然后再次单击AutoCompleteTextView/微调器,则显示的下拉列表没有应有的填充。左边的填充物不见了
我将适配器用作:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1, emailAddressesArray);
使用自定义布局文件并将其替换为android.R.layout.simple_list_item_1假设布局文件名为spinner_back.xml 然后
ArrayAdapter adapter=新的ArrayAdapter(上下文、,
R.layout.spinner_back,emailAddressesArray);
文件spinner\u back.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="10dp"
android:textSize="20sp" />
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="@string/what_is_your_favourite_programming_language_" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="36dp"
android:layout_marginTop="17dp"
android:ems="10"
android:text="">
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>
导入android.graphics.Color;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.widget.ArrayAdapter;
导入android.widget.AutoCompleteTextView;
公共类MainActivity扩展活动{
String[]language={“C”、“C++”、“Java”、“.NET”、“iPhone”、“Android”、“ASP.NET”、“PHP”};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//创建包含语言名称列表的ArrayAdapter实例
ArrayAdapter适配器=新的ArrayAdapter
(这是android.R.layout.select\u dialog\u项目,语言);
//获取AutoCompleteTextView的实例
AutoCompleteTextView actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
activ.setThreshold(1);//将从第一个字符开始工作
actv.setAdapter(适配器);//将适配器数据设置到AutoCompleteTextView中
actv.setTextColor(颜色为红色);
}
@凌驾
公共布尔onCreateOptions菜单(菜单菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}
}
文件:activity_main.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="10dp"
android:textSize="20sp" />
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="@string/what_is_your_favourite_programming_language_" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="36dp"
android:layout_marginTop="17dp"
android:ems="10"
android:text="">
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>
解决了这个问题。可能是个虫子。我的风格中有true
,这导致了这个问题。我将很快提交错误报告。发布您的XML文件?完成。但我不认为它是xml。在一个完全不同的应用程序中,spinner也出现了这种情况。你需要使用数组适配器。我已经添加了一个自定义文本视图。填充物甚至被移除。这个阵列适配器与我使用的有什么不同?我已尝试并将项目更改为android.R.layout。选择\u dialog\u项目
。但还是一样。@VipulKumar复制上面的代码n粘贴另一个活动并检查它…它对我来说工作正常…我做了。全新的活动。当我点击外部并再次点击AutoCompleteTexTview并开始输入时,填充消失了。@VipulKumar此代码对我有效,我认为这是另一个问题。。。在andriod手机中安装apk并运行它…我正在Android设备上测试它。Nexus6p,安卓M。您的配置是什么?
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="@string/what_is_your_favourite_programming_language_" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="36dp"
android:layout_marginTop="17dp"
android:ems="10"
android:text="">
<requestFocus />
</AutoCompleteTextView>
</RelativeLayout>