1
我想创建一个带有AutoCompleteTextView的DialogBox。没关系,我也可以显示自动完成列表和所有内容。问题是我不能削减对下拉列表的看法。自定义AutoCompleteTextView布局android
这是我在做什么在主要活动:
DialogBox DB = new DialogBox(MyActivity.this);
DB.createDialog();
而且,在创建另一个类的我:
public DialogBox(Context c)
{
context = c;
}
public void createDialog()
{
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
final View PopupLayout = inflater.inflate(R.layout.dialog_box, null);
builder.setView(PopupLayout);
//Autocomplete:
final AutoCompleteTextView textView = (AutoCompleteTextView) PopupLayout.findViewById(R.id.autocomplete_companies);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.dialog_box, R.id.autocomplete_companies, COMPANIES);
textView.setAdapter(adapter);
}
如果我试图改变R.layout.dialog_box我得到NullPointerExceptions或其他错误。
编辑:这是我的XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name"
android:scaleType="center" />
<AutoCompleteTextView
android:id="@+id/autocomplete_companies"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:hint="Company Name" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:hint="@string/username"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif"
android:hint="@string/password"
android:inputType="textPassword" />
任何想法,我做错了?
你能后的XML的内容,你所提到的错误的痕迹? –
新增...谢谢 – pacavied