Android: RadioButton within Nested Layout under RadioGroup falls out of Group - android

I'm trying to get some sensible positioning of my radiobuttons which are part of a RadioGroup. I was having trouble as my RadioGroup was sitting on top of the rest of my layout design, then I use margins to push the buttons around, the problem here is this works on one or two device layouts only. I thought I struck gold when I discovered I could define my RadioGroup then put in a RelativeLayout below which amongst other things contained one of the RadioButtons, then I repeat twice more. this gives me the layout I desire. Problem is, when I run the code, the RadioButtons act link standalone buttons :(
So two questions,
can I link these buttons back to the Group?
Is there a decent way to be able to define the layout of the RadioGroup Radiobuttons independently of the Group.
I am thinking an alternative may be independent RadioButtons and use code to enable/disable them, but that does kind of defeat the usefulness of RadioGroup.
thanks.
Here is my XML layout should you be curious.
<ScrollView android:id="#+id/scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden"
>
<RadioGroup android:id="#+id/calcBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout android:id="#+id/intervalBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/intervalHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/intervalHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/intervalHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/interval2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/intervalHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/intervalValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/intervalType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/intervalSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/recordBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/recordHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record Duration"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/recordHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/recordHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/record2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/recordHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/recordValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/recordType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/recordSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/playBackBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/playBackHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video Length"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/playBackHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="playBack help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/playBackHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/playBack2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/playBackHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byplayBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/playBackValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/playBackType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/playBackSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
</RadioGroup>
</RelativeLayout>
</ScrollView>

After looking around for a solution it looks the only way to do this is to use individual radio buttons and then programmically control there on/off states.

Related

How to configure xml of layout for preventing word cutting?

I have problems with word cutting at XML, look at the picture below:
As you can see word Delete is cut. Below is my layout for this part:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal"
android:weightSum="30"
android:baselineAligned="false">
<RelativeLayout
android:id="#+id/more_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:background="#color/gray_light"
android:paddingStart="10dp"
android:paddingEnd="10dp">
<ImageView
android:id="#+id/pict_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_more"
android:drawablePadding="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="More"
android:layout_below="#id/pict_1"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/archive"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="10"
android:background="#color/colorAccent"
android:paddingStart="5dp"
android:paddingEnd="5dp">
<ImageView
android:id="#+id/pict_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_inbox"
android:contentDescription="TODO" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:layout_below="#id/pict_2"
android:textColor="#color/white"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:background="#FF0000"
android:paddingStart="10dp"
android:paddingEnd="10dp">
<ImageView
android:id="#+id/pict_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_delete"
android:drawablePadding="10dp" />
<TextView
android:layout_below="#id/pict_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:textAlignment="viewStart"
android:textColor="#color/white"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
In general I noticed that it is caused by padding which pull elements inside parent layout. I tried to change it, but I see that word Archive is also can be influenced. How I can solve this problem with wrong layout xml?
add you third layout(delete) with wrap content and weight like below
<RelativeLayout
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="10"
android:background="#FF0000"
android:paddingStart="10dp"
android:paddingEnd="10dp">
<ImageView
android:id="#+id/pict_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_delete"
android:drawablePadding="10dp" />
<TextView
android:layout_below="#id/pict_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:textAlignment="viewStart"
android:textColor="#color/white"
android:textSize="12sp" />
</RelativeLayout>

How do I prevent one TextView from pushing the other out of the screen?

[SOLVED] Marked the working solution. #GIBIN THOMAS: this suggestion works as well (similar).
Below I've posted an issue which arise when the Scoring increases, making it to expand and therefor push the other TextView out of the screen. I've tried changing the Width and height in all kinds of ways for both the TextViews themselves and the Layout that's wrapping them, without any luck.
PROBLEM: Anyone got a good solution how to set my Layout and/or TextViews width and height to prevent the Scoring TextView from pushing the Lives TextView out of the screen?
.
This is my XML-file:
The layout & textviews below are all inside another layout (including 4 buttons, one imageview and another textView - excluded in the code)
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="#string/current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="205dp"
android:layout_marginStart="205dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="#string/lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lives_5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Try this layout:
use android:weightSum and android:layout_weight properly
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="SCORE"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Output:
This will fix your issue
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="Current Score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Scrore"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives 5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Please remove the strings i have added also if you have further doubts feel free to note down below
Please make sure to apply proper weight and other changes as follows :
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:text="current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lives_5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Just give the LinearLayout , layout_weight="5" .. Like
android:layout_weight="3" and make the android:layout_width = "0px"
Note="Set the layout weight according to your spacing" ...
The Linear Layout in which u have fitted these two textviews
Simply replace your current score linear layout with this relative layout and you are done.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentLeft="true"
android:text="current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</RelativeLayout>

How to adjust graphics to different screens resolution and rotation?

I making a checkers game and the code for the xml file is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/gamebackground" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="260dp"
android:layout_height="260dp"
android:layout_marginBottom="30dp"
android:background="#drawable/board_1_" >
<TableLayout
android:id="#+id/grid"
android:layout_width="221dp"
android:layout_height="213dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="16dp"
android:stretchColumns="*" >
</TableLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/opponent"
android:layout_width="150dp"
android:layout_height="17dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/player"
android:layout_width="150dp"
android:layout_height="17dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="110dp"
android:layout_height="30dp"
android:layout_marginRight="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="110dp"
android:layout_height="30dp"
android:layout_marginLeft="25dp"
android:layout_marginStart ="25dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/withdraw"
style="?android:attr/buttonStyleSmall"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/mybutton"
android:minHeight="10dp"
android:minWidth="70dp"
android:text="#string/Withdraw"
android:textSize="20sp" />
<Button
android:id="#+id/callfortie"
style="?android:attr/buttonStyleSmall"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:background="#drawable/mybutton"
android:minHeight="10dp"
android:minWidth="70dp"
android:text="#string/Callfortie"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I 'm adding 8 rows each row contains 8 button programmatically and setting these buttons to hold the checkers image ... the problem is I tested this on Nexus one emulator and looked like this
http://i59.tinypic.com/zwb6dj.jpg
but on different resolutions it looks like this
http://i61.tinypic.com/iwucls.jpg
So any help ? :)
It looks like you do not create xml file for multiple screen support.
You should follow multi screen support as per android developer's documents. Please follow below link for more info.
http://developer.android.com/guide/practices/screens_support.html

Android widget not showing up on the emulator screen

I have added some widgets on activity_main.xml, a layout file for main.java in android. When I ran the program on emulator, the last widget is missing in the emulator screen. What will be the reason? How to rectify it?
Here by I am giving below the code for activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:paddingBottom="50dp">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:src="#drawable/cmplnlogo"
android:id="#+id/imageViewLogo" />
<EditText
android:layout_marginTop="30dp"
android:layout_width="310dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:inputType="textEmailAddress"
android:hint="#string/signupUserHint"
android:textSize="15sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextEmail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewEmailValidator" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextPwd" />
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupCfmPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextConfirmPwd" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewPwdValidator" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/signInHint"
android:onClick="GoToLogin"
android:textColor="#FFFFFF"
android:id="#+id/textViewSignin" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/edittextstyle"
android:text="#string/SignUp"
android:onClick="SignUp"
android:textColor="#FFFFFF"
android:id="#+id/buttonSignUp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_terms"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textViewServiceTerms" />
</LinearLayout>
</LinearLayout>
I solved the problem mentioned in the above question by adding scrollview widget. I added the scrollview widget in the layout file for which all widgets are not appearing on the emulator. Remember scrollview only suppors only one direct file.
I had many layouts inside the layout file that enclosed different widgets. I enclosed all the layouts with in one layout. And then, enclosed that layout with scrollview. I am giving the snippet.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/scroll">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/registerUserName"
android:paddingBottom="10dp"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/enterRegisterUserName"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</Scrollview>

Switch between two or more edit text in android

Suppose I have two or more EditTextview in my layout and at run time by mistake I selected 2nd view and filled it with text; now I want to go to previous EditText view and on touch gain it's focus to write some text inside it.
But I am unable to do this. I can't gain focus of view and write it on click that particular view.
See the code below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/wall">
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textSize="30dp"
android:focusable="true"
android:hint="#string/Title" />
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:textSize="25dp"
android:paddingTop="45dp"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:ems="10"
android:focusable="true"
android:hint="#string/program" />
<TextView
android:id="#+id/CalDisplay"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="20dp"
android:layout_below="#+id/save" />
<Button
android:id="#+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/body"
android:layout_toRightOf="#+id/RunProgram"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Calculate" />
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Calculate"
android:layout_alignBottom="#+id/Calculate"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/RunProgram"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Save"
/>
<Button
android:id="#+id/RunProgram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/body"
android:layout_centerHorizontal="true"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Run" />
</RelativeLayout>
Try this...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:hint="Title"
android:textSize="15dp" />
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:layout_below="#+id/title"
android:layout_marginTop="5dp"
android:gravity="left"
android:hint="program"
android:inputType="textMultiLine|textNoSuggestions"
android:textSize="15dp" />
<TextView
android:id="#+id/CalDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/save"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/linearButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/body" >
<Button
android:id="#+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Calculate"
android:textColor="#ffffff" />
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"
android:textColor="#ffffff" />
<Button
android:id="#+id/RunProgram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
Replace RelativeLayout with LinearLayout. Because it seems like your EditText are overlapping each other (causing the problem in getting focus), or at least add some respective aligning to them.
For example, add the following to your second EditText:
android:layout_below="#id/title"

Categories

Resources