Android - Changing one xml id changes another - java

For some reason when I change the id of some buttons in xml files it changes the name of buttons in other xml files, this breaks the program, can someone explain what is happening here, are they perhaps linked somehow?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/third_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background_with_touch"
android:orientation="vertical" >
<Button
android:id="#+id/gift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/keep"
android:layout_alignParentTop="true"
android:layout_marginTop="125dp"
android:background="#drawable/gift_jewellery_but" />
<Button
android:id="#+id/keep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gift"
android:layout_centerHorizontal="true"
android:layout_marginTop="73dp"
android:background="#drawable/jewellery_self_but" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/third_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/main_background_with_touch"
android:orientation="vertical" >
<Button
android:id="#+id/existing_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/receiver"
android:layout_below="#+id/receiver"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:background="#drawable/generic_button"
android:minLines="2"
android:padding="20dp"
android:text="Do you have jewellery you want to upload a message to? \n (Are you a sender?)"
android:textColor="#color/white"
android:textSize="14sp" />
<Button
android:id="#+id/about_kiroco"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/existing_user"
android:layout_below="#+id/existing_user"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp"
android:background="#drawable/generic_button"
android:minLines="2"
android:padding="20dp"
android:text="I&apos;m not sure. I just want to try out my new jewellery. \n (Test Drive the Jewellery)"
android:textColor="#color/white"
android:textSize="14sp" />
<Button
android:id="#+id/receiver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_marginTop="172dp"
android:background="#drawable/generic_button"
android:minLines="2"
android:minWidth="60dp"
android:padding="20dp"
android:text="Do you have jewellery you want to receive a message from? \n (Are you a receiver?)"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="14sp" />
</RelativeLayout>
Those are two files where if I change the id of the layout of one it changes the name of the other to match it.

Related

How to have auto complete text in android studio without having to create an array

I watched this video of auto complete text. However, for this one he made an array with all but another video at 1:54 he shows off a text box that comes up that seems to be powered by Google. I am wondering how can I get this auto complete to come up for me? I know there is auto complete text you can get in Android Studio, but that is not what I want to use.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="onClick"
tools:context=".MainActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:layout="#layout/activity_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:orientation="horizontal"
android:layout_marginEnd="60dp">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.01"
android:ems="10"
android:hint="Enter starting location" />
<Button
android:id="#+id/B_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Search" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="98dp"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.01"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/B_hospital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Hospitals" />
<Button
android:id="#+id/B_restaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Restaurants" />
<Button
android:id="#+id/B_school"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Schools" />
<Button
android:id="#+id/B_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/map"
android:onClick="onClick"
android:text="To" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

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

How do i align both textviews on top of the drawable preventing them to pile up on eachother

Hello stackoverflow members. i am trying to achieve this:http://imgur.com/dqwOAOf
But for some reason the two texts cant take these positions like this http://imgur.com/lyYg8Ei
Could anyone explain what i am doing wrong?
and please forgive my artistic talents.
i have added the whole xml file.
The idea is that the two textviews timer and typegekookt are displayed in the center of backgroundtypegekookt evenly spaced out.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="#+id/eggContainer"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView android:id="#+id/eggtimerimage"
android:src="#drawable/eiwit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical"
/>
<ImageView android:id="#+id/backgroundtypegekookt"
android:src="#drawable/timerwijzer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
/>
<TextView
android:id="#+id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="zacht"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignTop="#+id/divider2"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:00"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#+id/divider2"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="#+id/divider1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/eggtimerimage"
android:layout_marginBottom="-30dp"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="#+id/divider2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/backgroundtypegekookt"
android:layout_alignStart="#+id/backgroundtypegekookt"
android:layout_alignRight="#+id/backgroundtypegekookt"
android:layout_alignEnd="#+id/backgroundtypegekookt" />
</RelativeLayout>
Instead of using the ImageView android:id="#+id/backgroundtypegekookt", use a RelativeLayout (or a LinearLayout) with that background (android:background="#drawable/timerwijzer"), and put your TextViews in it
This is what I mean:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/eggContainer"
android:layout_height="wrap_content"
android:padding="15dp"
>
<ImageView
android:id="#+id/eggtimerimage"
android:src="#drawable/eiwit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical"
/>
<LinearLayout
android:id="#+id/backgroundtypegekookt"
android:background="#drawable/timerwijzer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:orientation="vertical"
>
<TextView
android:id="#+id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="zacht"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/timer"
android:below="#id/typegekookt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="10:00"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_centerHorizontal="true"
/>
</LinearLayout>
<!-- You can use 2 Views instead of 2 TextViews, more efficiently -->
<!-- Anyway, in your screenshots I only see 1 - I guess you'll have to fix that -->
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="#+id/divider1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-30dp"
/>
<TextView
style="?android:listSeparatorTextViewStyle"
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignLeft="#id/backgroundtypegekookt"
android:layout_alignStart="#id/backgroundtypegekookt"
android:layout_alignRight="#id/backgroundtypegekookt"
android:layout_alignEnd="#id/backgroundtypegekookt"
/>
</RelativeLayout>
I also fixed the deprecated fill_parent to match_parent and #+id (anticipated reference) to #id (reference), where needed.
Also see my comments in the layout avout the 2 last views.

xml layout isn't working for me

I have a lot of info to put on one xml page. Now i got what I want in the positions i want. However instead of fitting all my data on 3 key parts without running into each other, It keeps running into the next TextView. I was wondering how to have it auto adjust.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/back" />
<TextView
android:id="#+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginTop="97dp"
android:text="#string/part_section_2" />
<TextView
android:id="#+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="#+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_makeup"
android:layout_below="#+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="#+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="#string/part_section_1" />
<TextView
android:id="#+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_info"
android:layout_below="#+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="#+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/part_makeup"
android:layout_marginTop="48dp"
android:text="#string/part_section_3" />
<TextView
android:id="#+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
would ScrollView work better? and how would switch this from this to ScrollView.
skin is 480x800
density is high(240)
Strings file - http://pastie.org/8534713
Changing to ScrollView (source):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
Edit:
As well as that, try changing your back button XML to this:
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/back" />
The problem was android:layout_alignParentBottom="true". The bottom ended up not going to the bottom of the page like you had before. The ScrollView cut back on the bottom of the layout.

Android relative layout issue

hello there today I tried to make a relative layout for android but I m getting errors in R.java:
"Unexpected end of declaration" 8 times
I passed a hour on it and I still didnt find anything
here is the code (I m sure its about xml not java code)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="#+id/playScrollView1">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="#+id/playRelativeLayout1">
<TextView
android:layout_height="wrap_content"
android:text="Convert to binary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:id="#+id/TextView1"
android:layout_alignParentTop="true"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:layout_below="#id/TextView1"
android:id="#+id/1"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:id="#+id/2"
android:layout_below="#id/1"/>
</RelativeLayout>
</ScrollView>
thanks in advance!
You need to use
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:layout_below="#+id/TextView1" // missing+
android:id="#+id/button1"/> // change id to button1 not 1
Same for other button
http://developer.android.com/guide/topics/ui/declaring-layout.html
Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute.
Example :
android:id="#+id/my_button"
The at-symbol (#) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file)
For relative layout
http://developer.android.com/guide/topics/ui/layout/relative.html
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/playScrollView1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:id="#+id/playRelativeLayout1">
<TextView
android:layout_height="wrap_content"
android:text="Convert to binary"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:id="#+id/TextView1"
android:layout_alignParentTop="true"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:layout_below="#+id/TextView1"
android:id="#+id/button1"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:id="#+id/2"
android:layout_below="#+id/button1"/>
</RelativeLayout>
</ScrollView>
Its just naming convention
Just change your id name of Buttons #+id/1 to #+id/One
it shall not be Numeric only it shall not start with Numeric
coz it will generate Field in R.java
like the following
public static final int 1=0x7f0a0032;
public static final int 2=0x7f0a0033;
As per convention it is WRONG a big WRONG
So Your code shall go like this
<Button
android:id="#+id/One"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/TextView1"
android:text="0" />
<Button
android:id="#+id/Two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/One"
android:text="0" />
OR completely
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/playScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/playRelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView
android:id="#+id/TextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Convert to binary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/One"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/TextView1"
android:text="0" />
<Button
android:id="#+id/Two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/One"
android:text="0" />
</RelativeLayout>
</ScrollView>

Categories