类TextView错误 - TextInputLayout内的AutoCompleteTextView崩溃。 TextInputLayout可以在里面处理textview吗?

时间:2016-03-18 09:25:57

标签: android android-adapter

错误导致类TextView - TextInputLayout内的AutoCompleteTextView崩溃。 TextInputLayout可以在其​​中处理textview吗?

设置适配器

    mRootView =  inflater.inflate(R.layout.fragment_add_buddy, container, false);
    mContext = this.getContext();
    mAdapter = new AddBuddyAutoCompleteAdapter(mContext, R.layout.add_buddy_auto_complete_drop_down, mBuddyList);
    mAutoCompleteTextView = (AutoCompleteTextView) mRootView.findViewById(R.id.autoCompleteBuddySearch);
    mAutoCompleteTextView.addTextChangedListener(filterTextWatcher);
    mAutoCompleteTextView.setAdapter(mAdapter);

Add_buddy_auto_comolete_drop_down.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout         xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">

<ImageView
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:layout_marginTop="1dp"
    android:layout_marginBottom="1dp"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="1dp"
    android:id="@+id/autoCompleteBuddyPic"
    android:src="@drawable/members6" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="25dp"
    android:textSize="20dp"
    android:textStyle="bold"
    android:layout_marginLeft="20dp"
    android:layout_toRightOf="@+id/autoCompleteBuddyPic"
    android:text="Hello"
    android:id="@+id/autoCompleteBuddyEmail" />

fragment_add_buddy.xml

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
xmlns:android="http://schemas.android.com/apk/res/android">

<!--TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="@string/addBuddySearchTitle"
    android:id="@+id/addBuddyEmailField"
    android:layout_marginTop="20dp"
    android:layout_alignParentTop="true" />-->


   <android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:theme="@style/addBuddy">
    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autoCompleteBuddySearch"
        android:hint="Email"
        android:layout_marginRight="50dp"
        android:layout_below="@+id/addBuddyEmailField"
        android:layout_centerHorizontal="true" />
     </android.support.design.widget.TextInputLayout>


<!--<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_marginTop="15dp"
    android:text="Nick Name"
    android:id="@+id/addBuddyNickNameView" />-->

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:theme="@style/addBuddy">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/addBuddyNickName"
        android:hint="Nick name"
        android:layout_marginRight="50dp"
        android:layout_centerHorizontal="true"/>
</android.support.design.widget.TextInputLayout>

<Spinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/relationshipSpinner"
    android:drawSelectorOnTop="true"
    android:entries="@array/relationshipArray"
    android:dropDownSelector="#06a5da" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/invite"
    android:id="@+id/addBuddySendInvite"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="44dp"
    android:layout_gravity="center_horizontal" />

GetViewMethod

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row;
    if(convertView==null) {
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        row = inflater.inflate(mResource, parent, false);
    } else {
        row = convertView;
    }
    Log.d("XXX", mSuggestions.get(position).mEmail+" "+position);
    //TextView email = (TextView) row.findViewById(R.id.autoCompleteBuddyEmail);
    //email.setText((CharSequence) mSuggestions.get(position).mEmail);
    return row;
}

崩溃详情:

> 03-18 09:17:36.304 4552-4552/com.tracoy E/AndroidRuntime: FATAL
> EXCEPTION: main
>                                                           android.view.InflateException: Binary XML file line #17: Error
> inflating class TextView
>                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
>                                                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
>                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
>                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
>                                                               at com.tracoy.adapters.AddBuddyAutoCompleteAdapter.getView(AddBuddyAutoCompleteAdapter.java:43)
>                                                               at android.widget.AbsListView.obtainView(AbsListView.java:2267)
>                                                               at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1188)
>                                                               at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
>                                                               at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1115)
>                                                               at android.widget.ListPopupWindow.show(ListPopupWindow.java:524)
>                                                               at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1081)
>                                                               at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:956)
>                                                               at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:938)
>                                                               at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
>                                                               at android.os.Handler.dispatchMessage(Handler.java:99)
>                                                               at android.os.Looper.loop(Looper.java:137)
>                                                               at android.app.ActivityThread.main(ActivityThread.java:4745)
>                                                               at java.lang.reflect.Method.invokeNative(Native Method)
>                                                               at java.lang.reflect.Method.invoke(Method.java:511)
>                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
>                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
>                                                               at dalvik.system.NativeStart.main(Native Method)
>                                                            Caused by: java.lang.UnsupportedOperationException: Can't convert to color:
> type=0x2
>                                                               at android.content.res.TypedArray.getColor(TypedArray.java:326)
>                                                               at android.widget.TextView.<init>(TextView.java:499)
>                                                               at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
>                                                               at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
>                                                               at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
>                                                               at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
>                                                               at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
>                                                               at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
>                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
>                                                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
>                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
>                                                               at  android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
>                                                               at com.tracoy.adapters.AddBuddyAutoCompleteAdapter.getView(AddBuddyAutoCompleteAdapter.java:43) 
>                                                               at android.widget.AbsListView.obtainView(AbsListView.java:2267) 
>                                                               at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1188) 
>                                                               at android.widget.ListView.measureHeightOfChildren(ListView.java:1244) 
>                                                               at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1115) 
>                                                               at android.widget.ListPopupWindow.show(ListPopupWindow.java:524) 
>                                                               at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1081) 
>                                                               at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:956) 
>                                                               at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:938) 
>                                                               at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 
>                                                               at android.os.Handler.dispatchMessage(Handler.java:99) 
>                                                               at android.os.Looper.loop(Looper.java:137) 
>                                                               at android.app.ActivityThread.main(ActivityThread.java:4745) 
>                                                               at java.lang.reflect.Method.invokeNative(Native Method) 
>                                                               at java.lang.reflect.Method.invoke(Method.java:511) 
>                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
>                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
>                                                               at dalvik.system.NativeStart.main(Native Method)

有人可以帮我这个吗? 谢谢你!

1 个答案:

答案 0 :(得分:-1)

  @Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View row;
row = inflater.inflate(R.layout.your_xml_file_name, container, false);
Log.d("XXX", mSuggestions.get(position).mEmail+" "+position);
AutoCompleteTextView email = (AutoCompleteTextView) row.findViewById(R.id.autoCompleteBuddyEmail);
email.setText((CharSequence) mSuggestions.get(position).mEmail);
return row;
}