Fix a layout above soft keyboard - java

I know this question has been on the internet for ages, but nothing seems to work in my case.
What's wrong
As seen in screenshots, the layout having the spinner is not pushed up and is overlapped by the soft keyboard. I want this layout to be placed just above the keyboard when it pops up.
My layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical"
tools:context="believe.cht.speak.MainActivity">
<ImageView
android:id="#+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="#drawable/ic_bubble"
android:tint="#color/blue" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="#drawable/shadow" />
<RelativeLayout
android:id="#+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/blue">
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
What I've tried
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan" //in the manifest, also tried combining the two
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //in the activity
<item name="android:windowActionBarOverlay">true</item> //in styles.xml

Try this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical">
<ImageView
android:id="#+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="#drawable/ic_message" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />
<ImageView
android:id="#+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="#drawable/ic_camera" />
<RelativeLayout
android:id="#+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimary">
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Manifest file
<activity android:name=".MyActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
OUTPUT

Adding to Nilesh's answer above, even though the code worked, it didn't work with my Java class. The reason was that I was hiding the statusbar with
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Using the code provided and leaving the statusbar untouched did the job. Don't know why. I would be helpful if anyone could explain this.

Try using a RelativeLayout instead of LinearLayout and add android:alignParentBottom="true" to your spinnerLayout

Related

screen isn't scrolling up when the keyboard appers

screen isn't scrolling up when the keyboard appers. I've read many answers saying to use android:windowSoftInputMode="something" I tried many of them
android:windowSoftInputMode="adjustPan|adjustResize"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="stateVisible|adjustResize"
android:windowSoftInputMode="stateVisible"
(also tried some others) none of them worked
I think the problem is on my xml which the most was generated by android studio "activity login" template.
is there any other way to do it?
my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.eduardo.academia.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eduardo.academia">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:windowSoftInputMode="stateVisible|adjustResize"
android:name=".LoginActivity"
android:label="#string/title_activity_login"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ExerciciosActivity"
android:label="#string/title_activity_exercicios"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
You should use a ScrollView for this. try below xml for your layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.eduardo.academia.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imageView"
android:layout_width="211dp"
android:layout_height="235dp"
app:srcCompat="#drawable/logo"
android:windowSoftInputMode="stateHidden"/>
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
<TextView
android:id="#+id/txtMudarSenha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="#string/forgot_password"
android:onClick="mudarSenha"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

EditText in Android not working/allowing to enter value

My EditText element is displaying well in popup window but its not allowing to enter values,I cant type anything inside that edittext element.
here i have attached xml code and screenshot.if you want my main activity class java code too let me know i can add it here.
xml code :
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/background_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="1dp"
android:background="#android:color/darker_gray">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:id="#+id/texttitle1"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#891800"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
/>
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>`
take the input type text noSuggestions and replace it with text
Find the solution:
1.In Manifest file please write windowSoftInputMode :
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden" />
Please put these lines in main LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
3.Please check the document
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Try with below XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="#android:color/darker_gray"
android:orientation="vertical"
android:padding="20dp">
>
<TextView
android:id="#+id/texttitle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Create Appoinment"
android:textColor="#891800"
android:textSize="25dp"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
<EditText
android:id="#+id/Easy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />
<Button
android:id="#+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="openNewActivity"
android:text="Save" />
<Button
android:id="#+id/dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to Menu" />
</LinearLayout>
</LinearLayout>
In my case, i had accidentally put android:descendantFocusability="blocksDescendants" to the parent layout,which blocks widgets inside this layout focusing. That is why, it was not working :)
If you have this line, please remove and it will work just fine

windowSoftInputMode does not pan Window

I don't know how to get my soft keyboard to show up under an TextView Field. It just covers up my Button and TextView.
I have used this link http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
as a reference. But it isn't working.
I have windowSoftInputMode="adjustPan" in the AndroidManifest file for my activity
<activity
android:name=".SearchView"
android:label="#string/title_activity_search_view"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.txisystems.inventory.MainActivity" />
</activity>
Here is what the screen looks like without the soft keyboard.
and the code to go with it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.mycompany.inventory.SearchView"
tools:showIn="#layout/activity_search_view">
<ImageView
android:id="#+id/logoView"
android:layout_width="225dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:src="#drawable/mylogo" />
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logoView"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
<EditText
android:id="#+id/txtSearchField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/logoView"
android:layout_alignLeft="#+id/logoView"
android:layout_alignRight="#+id/logoView"
android:layout_alignStart="#+id/logoView"
android:layout_below="#+id/progressBar2"
android:inputType="textShortMessage"
android:maxLength="17"
android:maxLines="1"
android:capitalize="none" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtSearchField"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:background="#color/colorPrimary"
android:backgroundTint="#color/colorPrimaryDark"
android:onClick="doSearch"
android:text="Search"
android:textColor="#color/buttontext" />
<TextView
android:id="#+id/lblSearchMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/button"
android:layout_alignLeft="#+id/button"
android:layout_alignRight="#+id/button"
android:layout_alignStart="#+id/button"
android:layout_below="#+id/button"
android:gravity="center_horizontal"
android:text="Please enter 4 or more characters."
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/error"
android:textStyle="bold" />
</RelativeLayout>
Here is what happens (I used Photoshop to simulate the screen.)
The keyboard can't be dismissed and it covers the button and the message area.
And here is what I want to happen through the magic of Photoshop.
Use this in the Activity (OnCreate) which hosts the XML:
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Activity relaunch when change from portrait to landscape mode

I build two XML-files for my activity. One in the layout Folder and the other in the layout-land folder. But when I change the orientation from portrait to landscape mode the activity relaunches. And thats exactly what i not want.
Because I'm plotting in three Graphs realtime data and the plotting should continue when I turn the Screen and not being interrupted or start new in any way.
Here is the first XML file in the layout-land Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
And here the second one in layout Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="#+id/sensor1_graph_Feuchtigkeit"
android:layout_below="#+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="#+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_below="#+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="#+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/mySwitch"
android:layout_alignBottom="#+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="#+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
In the Manifest XML it Looks like this:
<activity
android:name="com.TomKun.testgraph.DruckActivity"
android:label="#string/Sensor_1"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
If i have Manifest like this with
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
Then the layout does not change when I switch from Portrait to landscape mode. BUT the activity does not relaunch. Thats the one good thing
But if I do NOT use
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
the layout changes as i want but the activity is then relaunching.
So something in my implementation doesn't match.
Can anyone help me to solve this Problem?
I have seen that many people have similar Problems here on stackoverflow. But with these answers I couldn't solve my problem
Thanks in Advance!

java.lang.RuntimeException: Unable to start activity chronometer

I'm trying to create a chronometer, but I have a problem with the code. When I open the app on my tablet and on the emulator the app does not work, but this launches with no problem.
Please help me :(, or if you have another chronometer script available with milliseconds, please share it, as I haven't found anything else that would do what I need.
The error:
06-06 16:59:43.048 3724-3724/com.colorchronometer.rubiks E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.colorchronometer.rubiks/com.colorchronometer.rubiks.StopwatchActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.colorchronometer.rubiks" >
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".StopwatchActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:configChanges="keyboardHidden|orientation"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>
</manifest>
And the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/parentFrameLayout">
<ImageView
android:src="#drawable/bkgl"
android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/backgroundImageView">
</ImageView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:id="#+id/timerBackground"
android:background="#drawable/timerbackground.9">
<TextView
style="#style/timerText"
android:text="#string/timer"
android:id="#+id/timer">
</TextView>
<TextView
style="#style/timerText"
android:text="#string/timerMs"
android:id="#+id/timerMs"
android:textSize="30sp"
android:paddingTop="30sp">
</TextView>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:id="#+id/scrollView">
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:id="#+id/buttonArea"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ButtonstartButton- android-onClick=-startClick-
style="#style/buttonText"
android:layout_marginLeft="5dp"
android:background="#ff5cff9b"
android:textColor="#5F3A00"
android:shadowColor="#FBEBC5"
android:text="#string/startText"
android:layout_weight="0.5">
</Button>
<Button
style="#style/buttonText"
android:background="#FFFF6E75"
android:textColor="#2E2E2E"
android:shadowColor="#959597"
android:text="#string/resetText"
android:id="#+id/resetButton"
android:onClick="resetClick"
android:layout_weight="0.5">
</Button>
<Button
style="#style/buttonText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#ffff6e75"
android:textColor="#7A1100"
android:shadowColor="#DF726E"
android:text="#string/stopText"
android:id="#+id/stopButton"
android:visibility="gone"
android:onClick="stopClick"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true" >
</RelativeLayout>

Categories