在Honeycomb(Android 3.0)上运行的设备上使用AutoCompleteTextView组件(使用Motorola Xoom进行测试)时,我遇到了一个奇怪的问题.我使用以下堆栈跟踪得到Nullpointer异常:
致命异常:在android.widget.PopupWindow.getMaxAvailableHeight(PopupWindow.java:1152)在android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1054)在android.widget.ListPopupWindow.show(ListPopupWindow主显示java.lang.NullPointerException. java:516)在android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1047)的android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:931)在android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:914)at android.widget.Filter $ ResultsHandler.handleMessage(Filter.java:285)在android.os.Handler.dispatchMessage(Handler.java:99)在android.os.Looper.loop(Looper.java:126)在android.app .ActivityThread.main(ActivityThread.java:3997)在java.lang.reflect.Method.invokeNative(本机方法)在java.lang.reflect.Method.invoke(Method.java:491)在com.android.internal.os .ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)at com.android.internal.os.ZygoteInit.main(Zyg oteInit.java:599)at dalvik.system.NativeStart.main(Native Method)
请注意,我不会在包括Gingerbread在内的任何其他Android版本上获得此异常.它很难调试,因为我没有Honeycomb代码库的原始源代码.如果有人能帮助我,我将不胜感激.
谢谢,托里.
在我的AutoCompleteTextView中,在我从建议列表中选择一个项目后,文本不可见.我尝试过使用setTextColor(android.R.color.black),但它无法正常工作.我在Manifest中使用Theme.Light.有谁知道我能做什么?
提前致谢
提香
我想AutoCompleteTextView在我的应用程序中添加一个按名称和号码搜索联系人,如在带有android的本机SMS应用程序中所做的那样.我已经在互联网上看了很多东西,但我希望我的应用程序能够像Android短信应用程序一样显示它.这是我尝试的代码,只搜索Display_Name.
public class MakePayment extends Activity {
private AutoCompleteTextView mAuto;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.makepayment);
mAuto = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextViewTest);
ContentResolver content = getContentResolver();
Cursor cursor = content.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PEOPLE_PROJECTION, null, null, null);
ContactListAdapter adapter = new ContactListAdapter(this, cursor);
mAuto.setAdapter(adapter);
}
public static class ContactListAdapter extends CursorAdapter implements Filterable {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
mContent = context.getContentResolver();
}
@Override
public View newView(Context context, …Run Code Online (Sandbox Code Playgroud) 我正在尝试为 android 创建一个应用程序,我想在其中继续AutoCompleteTextView显示建议以减少用户的努力。目前我正在用我写的一个小代码进行测试,但我没有得到建议。我把代码贴出来,请帮我找出错误。
public class MainActivity extends Activity {
private ArrayList<Map<String, String>> objects;
private AutoCompleteTextView autotextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autotextView = (AutoCompleteTextView) findViewById(R.id.autocompleteView);
objects = new ArrayList<Map<String, String>>();
Map<String, String> NamePhoneType = new HashMap<String, String>();
NamePhoneType.put("Name", "John");
NamePhoneType.put("Phone", "1234567890");
objects.add(NamePhoneType);
NamePhoneType.put("Name", "Steve");
NamePhoneType.put("Phone", "4567890123");
objects.add(NamePhoneType);
ArrayAdapter<Map<String, String>> am = new ArrayAdapter<Map<String, String>>(
this, R.layout.list_item, objects);
autotextView.setAdapter(am);
}
}
Run Code Online (Sandbox Code Playgroud)
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/ccontName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" …Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌地图制作应用程序。我正在使用 AutoCompleteTextView 来获取地点建议。输出如下:

从图中可以看出,建议框的边框与 TextView 重叠。我在线性布局中使用带有 Textview 的自定义项目布局。
<?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="fill_parent"
android:background="#fff"
android:orientation="horizontal" >
<TextView
android:id="@+id/resultValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="#474040"
android:textSize="15sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
有没有办法降低建议窗口并删除或更改建议窗口灰色边框的颜色?
我有一个奇怪的问题AutoCompleteTextView.
我有一个AutoCompleteTextView显示城市输入时的建议.通过远程服务器检索城市列表JSON.当我使用软键盘或软键盘上的Mic按钮时,建议工作正常.AutoCompleteTextView确实显示建议的城市.
但是,当我尝试设置文本时,我有一个问题myAutoCompleteTextView.setText("Chi"),自动完成没有显示..我也试过myAutoCompleteTextView.append("Chi")但仍然没有运气..
适配器在那里,只是建议没有显示.
有小费吗?
谢谢.
我有一个AutoCompleteTextView我想应用一些样式的。代码在功能上有效,基本样式很好,但我想更改一些更高级的东西。具体来说:
自定义字体
我的搜索栏使用我的应用程序的自定义字体,但使用系统的默认字体显示预测行。以下是我为搜索结果设置字体的方法:
mSearchTextView.setTypeface(font.mAvenirLTStandardLight);
Run Code Online (Sandbox Code Playgroud)
从下拉菜单中删除阴影
The default dropdown options have a shadow and my app uses a more flat design. I'd like to remove that if possible.
Add radius to dropdown
I was able to round the radius of each result line, but I wasn't able to figure out how to apply a curve to the entire dropdown box.
Here are my applicable code sections:
private void setAutoCompleteListener() {
AutoCompleteAdapter adapter = new AutoCompleteAdapter(mContext,
R.layout.autocomplete_list_item, mLatLng);
mSearchTextView.setAdapter(adapter);
mSearchTextView.setOnItemClickListener(new …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现AutoCompleteTextView在登录活动中填充用户电子邮件以获得更好的用户体验.
为了符合Google的规范来阅读联系人,这个应用程序在运行时使用checkSelfPermission()方法请求用户的许可,我知道的很多工作.但是,当用户键入其用户电子邮件时,应在输入至少两个字符后显示下拉列表,这不会发生.
预期产量:
以下是我的实施(尝试).任何带代码(校正)示例的反馈都将非常感激.
的build.gradle:
...
compileSdkVersion 25
buildToolsVersion "25.0.2"
...
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中:
...
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
...
Run Code Online (Sandbox Code Playgroud)
activity_login.xml:
...
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:textColor="@android:color/white"
/>
</android.support.design.widget.TextInputLayout>
...
Run Code Online (Sandbox Code Playgroud)
LoginActivity.java :(很抱歉显示整个班级,但......只是在案件中.)
package com.company.product.activity;
import too.many.imports
import com.company.product.R;
import static android.Manifest.permission.READ_CONTACTS;
public class LoginActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
// UI references.
private EditText inputPassword;
private AutoCompleteTextView inputEmail;
private FirebaseAuth auth;
private ProgressBar progressBar;
private Button …Run Code Online (Sandbox Code Playgroud) 我致力于通过一些 REST API 实现自动完成建议(它实际上是 Nokia Here Geocoder Autocomplete API,但它并不那么重要)。我为AutoCompleteTextView.
public class GeoAutocompleteAdapter extends BaseAdapter implements Filterable {
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@Override
protected Filter.FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
// obtain some autocomplete data
filterResults.values = res;
filterResults.count = res.size();
return filterResults;
}
//...
}
//...
}
Run Code Online (Sandbox Code Playgroud)
据我了解,部分"obtain some autocomplete data"在线程池中运行。如果我以同步方式获得自动完成的结果 - 它的工作。例如,我可以使用HttpURLConnection和InputStream- 所有同步阻塞调用在这里工作得很好。
但是如果我需要在这里调用一些以异步方式运行的 API,比如通过 Callback\Listener 呢?
我怎样才能在 performFiltering 中调用这样的东西?
request.execute( …Run Code Online (Sandbox Code Playgroud) 我正在研究用户可以搜索数据的项目。为此,我已经实施了AutoCompleteTextView.
autoComplete.setAdapter(new ArrayAdapter<String>(CheckRiskActivity.this,
R.layout.auto_text_row, druglist));
autoComplete.setThreshold(1);
//druglist is my arraylist
Run Code Online (Sandbox Code Playgroud)
文本更改侦听器如下:
autoComplete.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// here I want to get the size of filtered array list every time when the user adds any character.
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
Run Code Online (Sandbox Code Playgroud)
说明:如果我的初始数组大小为 100 并且用户键入“a”,那么我想获取过滤数组的大小。
注意:我已经尝试过,autoComplete.getAdapter().getCount();但它在添加一个字符后给出了实际结果。
android filtering arraylist autocompletetextview android-adapter