Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

android - Error while placing a spinner inside Activity Group

I have an activity group containing 3 activities. When a button is pressed, I enter into this activity group and show the 1st activity. From the 1st activity I can goto 2nd activity and from 2nd activity I can goto 3rd activity.

I have a spinner in this 3rd activity layout. Problem is I am not able to click on that spinner. Error gets displayed showing:

12-31 11:29:41.082: ERROR/AndroidRuntime(474): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@43791b18 is not valid; is your activity running?

How can I solve this issue? Can anyone plz help...

Hi,

Please find the code for spinner attached:

setContentView(R.layout.requestinfo);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            PGDealerInfoRequestActivity.this, R.array.request_options, android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);

Inside requestinfo.xml,

<Spinner android:id="@+id/spinner" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textColor="@android:color/darker_gray"
            android:textSize="12sp" android:textStyle="bold"
            android:layout_marginLeft="10dp" android:layout_marginTop="8dp" />
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error was with the setContentView. I had given

setContentView(R.layout.mylayout);

Instead of that we should give,

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.mylayout, null);
this.setContentView(viewToLoad);  

And the spinner code is:

Spinner spinner = (Spinner) findViewById(R.id.spinner);

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.request_options, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...