0

我试图用字符串列表填充 Spinner。他在android中编译并运行,但是当我在Spinner中输入触摸时,程序停止并返回此错误:

android.content.res.Resources$NotFoundException:资源 ID #0x7f090003 类型 #0x12 无效

protected void onPostExecute(List<String> myList)
        {
            if (!myList.isEmpty())
            {
                ArrayAdapter<String> adp = new ArrayAdapter<String>(MyActivity.this, android.R.layout.simple_spinner_item, myList);
                adp.setDropDownViewResource(R.id.mySpinner);
                mySpinner.setAdapter(adp);
            }
            else
            {
                Toast.makeText(getApplicationContext(), "Warning.", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(myActivity.this, Preferences.class);
                startActivity(i);
            }
        }
4

1 回答 1

3

I think setDropDownViewResource method expects a layout resource ID.

You should replace

adp.setDropDownViewResource(R.id.mySpinner);

by

adp.setDropDownViewResource(R.layout.mySpinner);

And make sure (of course) that the file res/layout/mySpinner.xml exists

Or just use a default layout from the SDK:

adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
于 2012-11-23T14:07:37.910 回答