Android :: Android Handling Dynamically Added Views While Orientation Change

Oct 27, 2010

I have a ViewGroup that gets inflated dynamically. I have set Id's to all the inflated views. I am still not able to retain the inflated ViewGroup whenever the orientation is changed. Any particular check that i am missing here ?

Android :: Android Handling dynamically added views while orientation change


Android :: Dynamically Added Views In Linearlayout

Mar 10, 2010

Dynamically i am creating the linear layout and adding the views to linear layout every 5 sec i need to update data to linear layout from db when i check logger output it is adding to linear layout but gui it is not updating for every 5 sec updation i am using scheduleatfixed timer task.

View 2 Replies View Related

Android :: Orientation Problem While Dynamically Loading Views

Jul 8, 2009

I am trying to load textView and CheckBox view dynamically to a LinearLayout. i am getting some Orientation problem while doing the same.I want these two view in a single row but i its coming as in different raw.

Below is may code:

CODE:..............

layoutxml is

CODE:..................

View 3 Replies View Related

Android :: Orientation Change Handling On Widgets

May 31, 2009

Some of the content in my widget is based on custom drawing routines. is there any event i can listen for so i redraw and update this custom area when the orientation changes? currently my widget looks pretty screwed until the next widget update is requested.

View 3 Replies View Related

Android :: EditText Handling While Orientation Change

Feb 1, 2010

I have EditText in my application. While entering the text i am changing the portrait mode to landscape mode. Not the entered text is resetting. how do i handle this? Like if i change the orientation what ever entered text should be remain as it is.

View 2 Replies View Related

Android :: Handling Screen Orientation Change During Activity Start

Mar 12, 2010

I'm trying to find a way to properly handle setting up an activity where its orientation is determined from data in the intent that launched it. This is for a game where the user can choose levels, some of which are int portrait orientation and some are landscape orientation. The problem I'm facing is that setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) doesn't take effect until the activity is fully loaded. This is a problem for me because I do some loading and image processing during startup, which I'd like to only have to do once.

Currently, if the user chose a landscape level:

the activity starts onCreate(), defaulting to portrait discovers from analysing its launching Intent that it should be in landscape orientation continues regardless all the way to onResume(), loading information and performing other setup tasks at this point setRequestedOrientation kicks in so the application runs through onPause() to onDestroy() it then again starts up from onCreate() and runs to onResume() repeating the setup from earlier

Is there a way to avoid that and have it not perform the loading twice? For example, ideally, the activity would know before even onCreate was called whether it should be landscape or portrait depending on some property of the launching intent, but unless I've missed something that isn't possible. I've managed to hack together a way to avoid repeating the loading by checking a boolean before the time-consuming loading steps, but that doesn't seem like the right way of doing it. I imagine I could override onSaveInstanceState, but that would require a lot of additional coding. Is there a simple way to do this?

Solution:

As per Daniel's answer, this was actually quite easy to fix. I just needed to make a few small changes. In my 'menu' Activity, where the player would choose which level to play, I just had to add an if/else check to choose which class would be started by my Intent. This was done with a simple int representing portrait or landscape, determined when the player selected a level. I then created a second class extending my 'GameLogic' class; this is the class which contained most of the code for the game itself, rather than the menus, instructions, etc.

public class GameLandscape extends GameLogic{}

Literally that simple and completely empty. That way it inherited all the code from my previous activity where I had already coded it to handle things differently depending on the orientation. Lastly I just had to add a line to the manifest stating that GameLandscape would always run in landscape, and GameLogic would always run in portrait.

View 2 Replies View Related

Android :: Views - Orientation Change

Oct 1, 2009

Do Views know changes in orientation? In my case, I create popups from TextView and need to know when the orientation changes(porttrait<-- >landscape). I cannot depend on activity's onOrientationChange.

View 2 Replies View Related

Android :: Keep Dynamic Views Focused Through An Orientation Change?

Nov 9, 2010

If I have a layout with lots of EditText views in a LinearLayout and the user focuses the third one down and flips out the keyboard to start typing, the entire layout is destroyed and recreated through the activity lifecycle. When everything is done, however, the third EditText is given focus again and the user never knows that anything happened and types away.

I am creating a similar layout, but due to the nature of my data, I have to dynamically create the list of EditTexts, mixed with some other views. The default layout has one EditText at the top, a ScrollView with a LinearLayout child (which will be filled with EditTexts later), and some action buttons at the bottom. I fill the LinearLayout with all the EditText fields I need (based on extras passed via intent).

This part works quite well, but the way the activty handles Runtime Configuration changes is broken now (from a UI perspective). Now if the user focuses the third EditText (which was dynamically created via new EditText()) and flips out the keyboard, the layout is destroyed and recreated, but focus is always given to the permanent EditText at the top of the screen.

Is there something I need to do when adding my dynamic views to make sure they can keep focus through orientation changes? is there a way I can work around the issue and force focus to be given to the last view that had it before the change?

View 2 Replies View Related

Android :: Android GridView Reversing After Handling Orientation Change

Jun 19, 2010

My main application screen uses a GridView to display a grid of icons. Each icon has an image, name, and Intent. I have the Activity set to handle orientation changes so I can change the background. The onCreate method sets up the GridView with 3 test icons that don't do anything and a preferences icon which opens a PreferencesActivity:............

View 2 Replies View Related

Android :: ViewFlipper Switching Views On Screen Orientation Change

Jan 24, 2010

I have a 3 nested ViewFlippers which seem to be working ok except that when I change the screen orientation the view flip back to the first one of my views, giving the user the impression it went back a few steps.I am a bit stumped as to what to do and was hoping someone had some experience with this.

View 3 Replies View Related

Android :: Android - Wakelock & Handling Orientation Change

Jan 13, 2010

I'm using Wakelock in my application to prevent the phone from sleeping when the app is visible. The problem comes when there is an orientation change and the system destroys and re-creates the app in landscape mode. If the wakelock timer has expired in the background the system takes the release of wakelock as an opportunity to switch off the screen.

Edit: I should mention that I am setting Wakelock onResume, and releasing onPause - as I understand it, it's necessary to release then to prevent the app from leaking the wakelock. I need wakelock to continue through the orientation change. Below I've outlined a solution to this. Is this the preferred way to handle it, and are there any alternatives?

Create a service which holds wakelock (rather than the activity) and when the activity unbinds the service starts a countdown timer (for say 10 seconds) in which it will release wakelock when the timer expires if the activity does not rebind. If it was a simple orientation change the activity will rebind within that 10 seconds and so maintain wakelock, if it doesn't, wakelock will be released.

View 1 Replies View Related

Android :: Android - Dynamically Creating Controls And Orientation Change

Jan 29, 2010

Currently I am working on an Android application that is dynamically creating controls. Everytime a user would click a button a new EditText appears below the button and the user can interact with the EditText. However if the screen orientation changes, the EditText's that the user created also disappears.

Code sample of user creating a EditText: (located in a onClick(), p is basic layoutParamas, and layout is a LinearLayout located undearneath the button).........

View 1 Replies View Related

Android :: Dynamic Views Focused Through Orientation Change In Android?

Nov 9, 2010

I have an activity with an EditText on top and a ScrollView with a LinearLayout inside it. The LinearLayout is populated in the onCreate method with a set of dynamic views based on an object passed with the initiating Intent. This is typically a set of EditTexts. The result is a list of EditTexts each corresponding to a different piece of data (and the dataset being edited is quite variable, so the list needs to be created dynamically like this).

The problem is, when one of these views has focus, and the orientation changes (say the user flips out the keyboard to type), the focus snaps to the EditText at the very top of the Activity. This is certainly undesired behavior as the user didn't intend to type in the top EditText when he/she flipped out the keyboard.
How can I dynamically create my list of views like this and not have this undesirable focus changing behavior?

View 2 Replies View Related

Android :: Does Android Reuse Views During Orientation Change

Sep 23, 2010

Does android reuse views during a orientation change? I have a progress bar in my activity. I set the progress to 50%, and then do an orientation change. But for some reason, the progress bar maintain 50% after the orientation. I have call setprogress(0) in the onCreate() of my activity. And I have put 'printf' in anywhere I call setProgress(), i don't still don't understand why the progress bar maintains 50% everytime I do an orientation change?

View 2 Replies View Related

Android :: Handling Orientation Changes Yourself

Jun 3, 2010

From the documentation regarding the android:configChanges='orientation' attribute of the activity tag in the manifest:

Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

Why does it say this?

In the case of threads and networking requests via a service API library, a request could be made with a reference to the original Activity, and then an orientation change could occur, leaving the thread pointing to the old Activity.

While this can be fixed, it's tedious and ugly compared to just handling the configuration changes yourself.

Why should it be avoided?

I guess I should also ask: would this be an acceptable reason for doing the orientation configuration changes yourself?

View 2 Replies View Related

Android :: Handling Orientation Changes In AppWidgets

Apr 18, 2010

We have created an AppWidget that takes user inputted text into an EditText and displays a calculated amount of text inside a TextView on the Home Screen. We calculate the amount of text based on the AppWidgetInfo.minWidth, minHeight attributes. We do this to simulate scrolling; we cut up the user-inputted text into chunks that will fit into the widget and swap them based on button clicks.

When we save the widget with the device in Landscape mode, it calculates the appropriate amount of text for Landscape mode and displays it in the widget. The problem is when the user changes orientation of the device to Portrait mode (without opening the widget and resaving the text), the calculated amount of text for Landscape mode is still displayed. This also happens in the vice versa case (the user is in Portrait and saves, etc.)

How can we tell our AppWidget to recalculate the amount of text displayed on screen orientation change? Is this possible? How would you solve this problem?

View 5 Replies View Related

Android :: Handling Screen Orientation

Jul 6, 2010

My project is working fine when i hold my HTC device vertical.But the moment i rotate my screen 90degrees , it throws a force close error.Starts all over again, runs fine until i again change the orientation.How do i handle it ?

View 1 Replies View Related

Android :: WebView / Handling Orientation Changes

Jun 16, 2009

Just started working with the webview. The issue is performance following rotation. The WebView has to reload the page, which can be a bit tedious.What's the best of of handling an orientation change without reloading the page from source each time?

View 2 Replies View Related

Android :: Handling Orientation Changes That Occur In Another Activity

Jun 3, 2010

I am having an interesting problem and would appreciate any advice. My app uses WebView as its primary view. Using a javascript hook, it can launch the camera so the user can take a picture. The camera is launched using: Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

When the camera starts, it makes sense to use landscape mode, so the user naturally turns the phone on its side. After the user takes a picture, control returns to my launching Activity (actually, my Acitivity gets restarted because it usually gets destroyed to free up memory for the camera on my Moto Droid). When my WebView gets recreated, I restore its state from the Bundle I saved in onSaveInstanceState().

Now everything looks ok, except the phone is still in landscape mode. However, when the user turns the phone upright bringing back into portrait mode, my WebView takes up only half of the screen. Somewhere along the way, the scale of my WebView got lost. This seems like such a minor issue, but it is driving me crazy.

Does anyone have an idea why this might be happening? What is the correct way to preserve the scale of my WebView? I am hesitant to hard code any scale factors because what looks good on my device may not be the same for another.

View 8 Replies View Related

Android :: Setting Attributes Of An EditText Added Dynamically In Phone

Nov 17, 2010

I am developping an android app which downloads an xml and displays a layout with a number of edittexts, checkboxes, spinners, etc. added dynamically like this:

LinearLayout ll = new LinearLayout(this);
EditText nameField = new EditText(this);
ll.addView(nameField);
ScrollView sv = new ScrollView(this);
sv.addView(ll);
setContentView(sv);

I'm having trouble with setting some properties to an EditText added this way. For examle android:maxLength attribute can easily be set in an xml layout but I found no method to do the same in the java code. How can I do it when hawing to add dynamically?

View 2 Replies View Related

Android :: Dynamically Changing Views

Jun 18, 2010

I'm trying to learn how to build apps for Android. The first simple app, which will become a component of a bigger app I hope to build, is to have a button on the screen where, when tapped, it adds something new to the view. For instance: Imagine a layout that only has a button:

[Create!]

When that button is pressed, the view gets a new row added to it:

[Create!]
A Something!..............

View 2 Replies View Related

Android :: Creating Views Dynamically

Dec 13, 2009

In my main.xml layout file, I define a FrameLayout. Then in another layout file (say overlay.xml), I define another layout.

At runtime (onCreate) I want to create a new View object, set it's layout with overlay.xml, and add it to the frame dynamically. I need access to the elements of the overlay, to change text etc.

View 4 Replies View Related

Android :: Add Views Dynamically Or On Top Of Other Components

Nov 19, 2010

I use a LinearLayout and first I have a MapView and below the map I have a TableLayout with informations fields.

Now I would like to add additional information fields (e.g. a new TableLayout) when the user select a specific menu item on the Options Menu. I would like to have these fields either between the MapView and the TableLayout, or on top of the bottom area of the MapView.

How can I add this TableLayout with additional information fields dynamically after the user has selected a menu item? How can I show it below the MapView or on top of the bottom area of the MapView?

View 1 Replies View Related

Android :: GenerateId - Method For Dynamically Generated Views

Aug 30, 2010

Is there (or should there be), a generateId() method for dynamically generated Views? Take the RadioGroup example in APIDemos|App|Views. Radio buttons are added dynamically. For each button, you have to call setId(). To be notified when a radio button is selected, you register a onCheckedChange listener on RadioGroup and the callback method is oncheckedChange(RadioGroup, int checkedId). Since we are notified only the id of the checked view, shouldn't there be a way to uniquely generate the id? Say, a View.generateId() method... In the example, the ids are statically defined in ids.xml. However this limits the number of radio buttons. I have a real world example too: a Radiogroup with each choice representing a Wifi hotspot. So one cannot know in advance the number of hotspots.

View 10 Replies View Related

Android :: Using TabHost With Dynamically Built - Pre-existing Views

May 25, 2009

I have a remove assistant app, which allows customers to perform a subset of functions of a desktop application, untethered. Results are communicated back & forth via messages left at a license server. In order to have a single source for the logic of the assistant, yet run on multiple platforms (Swing, MIDP, & Android), I write a driver composed of Database, Network, & Display pieces.

The Android driver is nearly complete, but I run into a brick wall when it comes to Tabs. All views are instanced calling code, not XML defined. I already have the view before I try to add it.

I tried sub- classing TabHost:

CODE:.................

As is shown in the code, it errors in setup. Looking further down in setup() I will also get this exception too: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent

Is there a way to trick setup() into instancing me mTabWidget & mTabContent members?

View 4 Replies View Related

Android :: Dynamically Sizing Views As A Percentage - Or Similar

Mar 8, 2010

To use as an example: lets say that I have 2 EditTexts and one Button that I'm using as a login form. I want the EditTexts to be the same size, one after the other, with the login Button half their widths. Something like this:

The only way that I've been able to find to make the button 1/2 the width (but still maintain it's dynamic sizing) is to use a TableLayout with an empty view as the first field. Something like this:

CODE:.............

That feels like a god-awful hack and there has GOT to be a better way. Do you know of one?

View 1 Replies View Related

Android :: Generate / Create Ids For Views That Are Created Dynamically?

Oct 15, 2010

I am trying to dynamically create a interface using a relative layout. I would like to align different views with each other and am finding the need to know the id of a previously created view so that I can use them in subsequent layout params.

Is there a preferred or best way to generate or create ids for views that are created dynamically?

View 2 Replies View Related

Android :: Apply Styles To My Views At Runtime Dynamically?

Aug 13, 2010

I'd like to dynamically apply styles to my views at runtime.
Is there any method like View.setStyle(int style)?

View 1 Replies View Related

Android :: Orientation Change - Dialog Above Activity With Fixed Orientation

May 14, 2009

I have created an activity for my game which handles all orientation changes by itself and has a fixed "portrait" layout. Actually it uses the accelerometer and is rendered using 2D canvas methods. If the level has been completed I show up a highscore dialog in which the user can enter his name. The dialog is floating above the underlying level screen which gets blurred out nicely. This generally works.

Problem is that the dialog does not get rotated if the orientation of the phone changes. So even if the keyboard is exposed the dialog is shown in portrait mode instead of landscape. I have tried to use an activity with dialog theme instead but the behavior didn't change. After several tries it seems that I have found the reason for this: Once there's an activity with fixed orientation in the activity stack then all subsequent activities keep this orientation, too. They will not react on orientation changes anymore (e.g. if the keyboard gets exposed).

After upgrading to 1.5 SDK the described behavior changed a little bit. Now at subactivities indead react on orientation changes like expected. However, the need to have an opaque background! That means that neither dialogs nor activities with dialog theme will work. Those will stick with the orientation of the underlaying activity. So my workaround is to first start a sub-activity with an opaque black background. This activity then shows my highscore dialog on top. It looks quite okay but I wonder if there's a better solution? Is it possible to show a dialog above a fixed portrait or landscape activity which automatically adapts to orientation changes?

View 3 Replies View Related

Android :: Dynamically Adjust Column And Row Of A Table Layout Based On Orientation

Mar 9, 2010

Is it possible for my android application to dynamically adjust the no of column and no of row of my TableLayout based on orientation?

For example, when in landscape mode, the TableLayout is 3x2 and when
in portrait mode, the TableLayout is 2x3?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved