I decided to try using a ViewAnimator, and I discovered that it works, unless I remove the current view before displaying the new one. If I do that, then it behaves the same way as before. This got me to thinking that there must be something I can do to make it work even if I remove the old view first. After some experimenting I discovered that if I set the visibility of the view that I am removing to INVISIBLE before I remove it, then it works fine. This is true even if I use the setContentView function to set the current view, as I originally had it.
Thanks much for your help! On Oct 10, 4:20 pm, Mark Murphy <mmur...@commonsware.com> wrote: > It is possible you are running into an Android bug. Calling > setContentView() repeatedly is certainly supported, but AFAIK it's a > bit off the mainstream, and so there may be lingering issues. > > If your goal is simply something that works, consider using a > ViewAnimator (e.g., ViewSwitcher) as a container, or simply change the > visibility of various components. > > Beyond that, I would recommend you package up a full project (not just > this class file) and log this as an issue onhttp://b.android.com. > Supplying a full project will make it incrementally easier for > somebody to give your code a whirl and make it incrementally more > likely that you'll get useful feedback. > > > > On Sun, Oct 10, 2010 at 6:36 PM, John Gaby <jg...@gabysoft.com> wrote: > > I have a put together a very simple program which exhibits this > > behavior. Run the following program and then do the following > > > 1) Click in the edit control of the first page which should bring up > > the soft keyboard > > 2) Using the soft keyboard type 'aaa' > > 3) Click the 'Press This' button > > 4) The view switches to the next page > > 5) Click in the edit control of this new page and using the soft > > keyboard type 'bbb' > > 6) Click the 'Press This' button > > 7) You should now see the first page with the edit control which still > > has the 'aaa' text in it. > > 8) Click in that edit control and enter 'ccc' via the soft keyboard. > > 9) Note that nothing appears to happen (except you get some > > MediaPlayer errors in LogCat???) > > 10) Click the "Press This' button which switches back to the second > > page. > > 11) Note that the 'ccc' you typed is in this edit control > > > Clearly, even though the second page is no longer visible, it somehow > > still has the focus. I have tried using the 'requestFocus' function > > to set the focus into both the EditText control and the LinearLayout > > view of the currently visible view, but this does not seem to have any > > effect. Can someone please tell me how to make this work? > > > Thanks > > > package com.gabysoft.testandroid; > > > import android.app.Activity; > > import android.os.Bundle; > > import android.view.View; > > import android.view.View.OnClickListener; > > import android.widget.Button; > > import android.widget.EditText; > > import android.widget.LinearLayout; > > import android.widget.LinearLayout.LayoutParams; > > > public class TestAndroid extends Activity implements OnClickListener { > > /** Called when the activity is first created. */ > > LinearLayout ll1; > > LinearLayout ll2; > > boolean one = true; > > > LinearLayout CreatePage() > > { > > LinearLayout ll; > > EditText et; > > > ll = new LinearLayout(this); > > et = new EditText(this); > > LayoutParams lp = new LinearLayout.LayoutParams(100, 50); > > et.setLayoutParams(lp); > > Button btn = new Button(this); > > btn.setText("Press This"); > > btn.setOnClickListener(this); > > > ll.addView(et); > > ll.addView(btn); > > > return(ll); > > } > > > �...@override > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > > ll1 = CreatePage(); > > ll2 = CreatePage(); > > > setContentView(ll1); > > } > > > �...@override > > public void onClick(View arg0) > > { > > if (one) > > { > > setContentView(ll2); > > } > > else > > { > > setContentView(ll1); > > } > > > one = !one; > > } > > } > > > On Oct 9, 10:35 am, John Gaby <jg...@gabysoft.com> wrote: > >> I have an app where the user is entering some data via an EditText > >> control. This is done by alternating between 2 pages each of which > >> obtains one piece of data. When I start, I create the first page and > >> make it active by calling the setContentView for the activity. I also > >> set the focus into the EditText control on this page. When I do that, > >> I am able to bring up the soft keyboard and type text into the > >> control. > > >> I then press a 'Next' button, which brings up the second page. I > >> create this page which has another EditText control, and make it > >> active by calling the setContentView. Once again, this works > >> correctly, and I am able to enter text into the control. > > >> When I press the 'Next' button again, the first page is then make > >> active again (I am reusing the origonal page, and do not recreate > >> it). However, when I do this, I can no longer type text with the soft > >> keyboard and have it go into the EditText control. The control shows > >> a blinking cursor as if it has focus, but if I type on the soft > >> keyboard, nothing happens, except I get the following errors in > >> LogCat: > > >> 10-09 17:28:52.722: ERROR/MediaPlayerService(30): error: -2 > >> 10-09 17:28:52.722: ERROR/MediaPlayer(52): Unable to to create media > >> player > >> 10-09 17:28:52.722: WARN/AudioService(52): MediaPlayer IOException: > >> java.io.IOException: setDataSource failed.: status=0x80000000 > > >> Note that if I don't bring up the soft keyboard and use the hardware > >> keyboard instead, everything seems to work correctly. > > >> Obviously, I am doing something wrong here, but I cannot figure out > >> what. Can anyone give me a clue as what is happening here? > > >> Thanks. > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > _Android Programming Tutorials_ Version 3.0.1 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en