朋友们,我在创建alertbox时遇到了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;
}
}
请问有解决方案吗?。
答案 0 :(得分:0)
您需要使用以下方式。
View viewToLoad = LayoutInflater.from(
getActivity().getApplicationContext()).inflate(
R.layout.custom_autocomplete, null);
您的套餐必须相同:com.example.netmdapp1.customViews