2
@Override
public boolean onOptionsItemSelected(MenuItem item) {       
RelativeLayout screen = (RelativeLayout) findViewById(R.id.RelativeLayout01);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    switch (item.getItemId()) {
    case R.id.menu_control: {
    inflater.inflate(R.layout.adv_video, screen, true);
    adapter = new ArrayAdapter<String>(screen.getContext(), R.id.spinner1, new String[]{"Author","ISBN","Keyword","Title"});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
spinner = (Spinner) screen.findViewById(R.id.spinner1);
spinner.setAdapter(adapter);

进一步在代码按钮、编辑文本等中。如果评论spinner.setAdapter(adapter);- 一切正常,带有空微调器列表。

这是日志:

logcat:
11-02 14:02:01.735: E/AndroidRuntime(1865): FATAL EXCEPTION: main
11-02 14:02:01.735: E/AndroidRuntime(1865): android.content.res.Resources$NotFoundException: Resource ID #0x7f06000e type #0x12 is not valid
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.content.res.Resources.getLayout(Resources.java:731)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:243)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:699)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.TableRow.onMeasure(TableRow.java:112)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:384)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:307)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:699)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.View.measure(View.java:8173)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.os.Looper.loop(Looper.java:123)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at java.lang.reflect.Method.invokeNative(Native Method)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at java.lang.reflect.Method.invoke(Method.java:521)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-02 14:02:01.735: E/AndroidRuntime(1865):     at dalvik.system.NativeStart.main(Native Method)
11-02 14:02:01.743: W/ActivityManager(1306):   Force finishing activity de.mjpegsample/.MjpegSample
4

1 回答 1

6

您可以设置( )的 id ,而不是提供要使用的布局文件的 id。实例化应该是这样的:ArrayAdapterSpinnerR.id.spinner1ArrayAdapter

adapter = new ArrayAdapter<String>(screen.getContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"});

或者提供id另一个布局文件(R.layout.layout_file_name),它只包含一个TextView.

于 2012-11-02T11:32:10.483 回答