0

このコード中に infalte 例外が発生しました

public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
appContext=getActivity().getApplicationContext();
myContext=getActivity();
}

private void createAlertBox(final AppointmentRow appointmentRow)
{
final Dialog dialog = new Dialog(myContext, R.style.Dialog);
View layout = LayoutInflater.from(appContext).inflate(R.layout.custom_autocomplete, null);
String[] from={"id","name"};
.....................
.....................
}

次の行で例外が発生しました。

View layout = LayoutInflater.from(appContext).inflate(R.layout.custom_autocomplete, null);

例外は Android.View.InflateException です。解決策はありますか?

    <com.example.netmdapp1.customViews.CustomAutoCompleteTextView
    android:id="@+id/customautocomplete"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:completionThreshold="1"
    android:ems="10"
    android:hint="Patient name"
    android:scrollbars="vertical"
    android:textColor="@android:color/black"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:background="@drawable/edittext_modified_states"
    android:layout_marginTop="5dp">
    <requestFocus />
</com.example.netmdapp1.customViews.CustomAutoCompleteTextView>
</LinearLayout>
</LinearLayout>

これは Xml の部分です。

4

2 に答える 2

0

次の変更を行うことをお勧めします。

LayoutInflater layoutInflater = (LayoutInflater) your_Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = layoutInflater.inflate(R.layout.custom_autocomplete, null); 

次に、この「ビュー」を、単に findViewById() のように使用するのではなく、findViewById() で使用します。

TextView tv = (TextView) view.findViewById(R.id.your_textView);
于 2013-08-16T09:48:56.120 に答える