嗨朋友们,我在创建警报框时遇到了 Android.View.InflateException。
private void createAlertBox(final AppointmentRow appointmentRow)
{
final Dialog dialog = new Dialog(myContext, R.style.Dialog);
View layout = LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.custom_autocomplete, null);
.........}
问题出在一线
View layout = LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.custom_autocomplete, null);
这是错误日志。
08-16 15:35:00.820: E/AndroidRuntime(3898): FATAL EXCEPTION: main
08-16 15:35:00.820: E/AndroidRuntime(3898): android.view.InflateException: Binary XML file line #36: Error inflating class com.example.netmdapp1.customViews.CustomAutoCompleteTextView
08-16 15:35:00.820: E/AndroidRuntime(3898): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
这是发生 xml 部分的问题。
<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>
下面给出了 CustomAutoCompleteTextView.java
public class CustomAutoCompleteTextView extends AutoCompleteTextView {
int mythreshold;
HashMap<String, String> hm;
PatientDetail patient;
public CustomAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
hm = new HashMap<String, String>();
hm.put("id", "" + 0);
// TODO Auto-generated constructor stub
}
@Override
protected CharSequence convertSelectionToString(Object selectedItem) {
hm = (HashMap<String, String>) selectedItem;
return hm.get("name");
}
@Override
public void setThreshold(int threshold) {
int myThreshold = threshold;
if (myThreshold < 0) {
myThreshold = 0;
}
mythreshold = myThreshold;
}
@Override
public boolean enoughToFilter() {
return getText().length() >= mythreshold;
}
@Override
public int getThreshold() {
return mythreshold;
}
public String getid() {
return hm.get("id");
}
public void setElement(HashMap<String, String> hm2) {
hm = hm2;
}
}
请问有什么解决办法吗。。