Reputation: 61
I have a problem when creating an AutoCompleteTextView within a dialog
My code to create the view is
private void setPalleteOnClicks() {
ImageButton newMethod = (ImageButton) findViewById(R.id.new_method);
newMethod.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
final Dialog dialog = new Dialog(AndroidPDStoreActivity.this);
dialog.setContentView(R.layout.method_creation);
dialog.setTitle("New Method Creator");
//String[] types = {"int", "double"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(AndroidPDStoreActivity.this,R.id.autoComplete, getResources().getStringArray(R.array.types));
AutoCompleteTextView actv = (AutoCompleteTextView) dialog.findViewById(R.id.autoComplete);
actv.setThreshold(1);
actv.setAdapter(adapter);
dialog.show();
}
});
}
My Xml file looks like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Return Type: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<AutoCompleteTextView
android:id="@+id/autoComplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:dropDownHeight="100sp"
android:text="" >
</AutoCompleteTextView>
</LinearLayout>
</LinearLayout>
The exception i am getting is
08-14 14:11:14.524: E/AndroidRuntime(24167): FATAL EXCEPTION: main
08-14 14:11:14.524: E/AndroidRuntime(24167): Process: com.android.pdstore, PID: 24167
08-14 14:11:14.524: E/AndroidRuntime(24167): android.content.res.Resources$NotFoundException: Resource ID #0x7f050024 type #0x12 is not valid
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2314)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.content.res.Resources.getLayout(Resources.java:939)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.AbsListView.obtainView(AbsListView.java:2255)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1585)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1167)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.ListPopupWindow.show(ListPopupWindow.java:554)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1096)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971)
08-14 14:11:14.524: E/AndroidRuntime(24167): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:953) .....
I have tried clean and deletion of R.java files as stated by other posts, but this did not help. The problem only occurs when the drop down menu actually needs to be shown.
Upvotes: 0
Views: 482
Reputation: 26198
problem:
new ArrayAdapter<String>(AndroidPDStoreActivity.this,R.id.autoComplete, getResources().getStringArray(R.array.types));
As you can see the second parameter in the constructor of the ArrayAdapter
you are supplying an id from your AutoCompleteTextView
in the xml which catch Resources$NotFoundException
. It is expecting a layout for the instantiating the views not an id from AutoCompleteTextView
.
The resource ID for a layout file containing a layout to use when instantiating views.
solution:
you need to call the native android layout for AutoCompleteTextView
to use as a layout for instantiating the views.
sample:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(AndroidPDStoreActivity.this,
android.R.layout.simple_dropdown_item_1line,
getResources().getStringArray(R.array.types));
Upvotes: 1
Reputation: 25018
Is this a problem related to multiple screen sizes where you have layout-[qualifier]
folders? It may happen that you have the resource for one screen size and not for the other. If it is, you may want to move some of your layouts (the ones that will not change based on screen sizes) to the unqualified layout
folder rather than keeping it in specific, size-based folders.
Upvotes: 0