Android 活动启动时需要在对话框中显示自动完成文本视图
我的Android 活动启动时需要在对话框中显示自动完成文本视图,android,dialog,android-alertdialog,autocompletetextview,Android,Dialog,Android Alertdialog,Autocompletetextview,我的工具栏中有一个自动图文视图,我需要在对话框或警报对话框上查看。我已经为此搜索视图设置了建议任何人请帮助我以最简单的方式在对话框上添加相同的自动完成 我的代码如下: AutoCompleteTextView autoservice; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac
工具栏中有一个自动图文视图
,我需要在对话框
或警报对话框
上查看。我已经为此搜索视图设置了建议
任何人请帮助我以最简单的方式在对话框
上添加相同的自动完成
我的代码如下:
AutoCompleteTextView autoservice;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grids);
sharedPreferences = getSharedPreferences(MyPref, Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
keypad= (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
autoservice=(AutoCompleteTextView)findViewById(R.id.auto);
if(sharedPreferences.getString("locationStatus","")!="")
autoservice.setText(sharedPreferences.getString("locationStatus","").substring(0,1).toUpperCase()+sharedPreferences.getString("locationStatus","").substring(1));
final String[] web = getResources().getStringArray(R.array.web);
TypedArray ar = getResources().obtainTypedArray(R.array.imageId);
int length = ar.length();
final int[] imageId = new int[length];
for (int i = 0; i < length; i++)
imageId[i] = ar.getResourceId(i, 0);
ar.recycle();
autoservice.setThreshold(2);
autoservice.addTextChangedListener(this);
autoservice.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
autoservice.getLayoutParams().width = LinearLayout.LayoutParams.MATCH_PARENT;
autoservice.setText(null);
}
});
autoservice.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
keypad.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
autoservice.setFocusable(false);
autoservice.setFocusableInTouchMode(true);
autoservice.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT;
autoservice.setText((String)parent.getItemAtPosition(position));
editor.putString("locationStatus",(String)parent.getItemAtPosition(position));
editor.commit();
locationStatus = sharedPreferences.getString("locationStatus", "");
}
});
AutoCompleteTextView自动服务;
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_网格);
SharedReferences=getSharedReferences(MyPref,Context.MODE\u PRIVATE);
editor=SharedReferences.edit();
键盘=(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务);
autoservice=(AutoCompleteTextView)findviewbyd(R.id.auto);
if(SharedReferences.getString(“locationStatus”,下称“)!=”)
autoservice.setText(SharedReferences.getString(“locationStatus”),子字符串(0,1).toUpperCase()+SharedReferences.getString(“locationStatus”),子字符串(1));
最终字符串[]web=getResources().getStringArray(R.array.web);
TypedArray ar=getResources().obtainTypedArray(R.array.imageId);
int length=ar.length();
最终整数[]图像ID=新整数[长度];
for(int i=0;i
这是我的toobar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Irrelevant stuff -->
<!-- Must be last for right layering display -->
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@drawable/buttonshape"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<AutoCompleteTextView
android:background="@drawable/button_shape"
android:id="@+id/auto"
android:textStyle="bold"
android:textSize="15sp"
android:hint="Location"
android:textColorHint="#BDBDBD"
android:drawableRight="@mipmap/ic_keyboard_arrow_down_white_24dp"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
</android.support.v7.widget.Toolbar>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
style="@style/MaterialSearchViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</FrameLayout>
以上给出的是我的xml文件和java文件,提前谢谢,对不起我的英语