SOLVED main.xml not being read?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

SOLVED main.xml not being read?

Postby bgoody » Sun Sep 20, 2009 11:54 pm

Hi. I have set up everything on Eclipse and have got my program to show up on the emulator with no problems. I can make changes to the Properties page of the main.xml and they show up in the little simulator there.

However they don't show up in the emulator unless I change the src/blabla/java file directly for example

btnZero.setTextColor(Color.RED);

I have tried, restarting, cleaning etc. I was under the impression that anychanges made to main.xml were compiled when the file was saved. It does something but the app doesn't change.

There are no Problems and the Error Log says nothing.
Ideas? Thanks, Brian

ADDENUM This is the line that's not being changed:
android:textColor="#2E4A4AFF"
Is there something wrong with this???
Last edited by bgoody on Tue Sep 22, 2009 1:46 am, edited 2 times in total.
bgoody
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Sep 20, 2009 2:39 pm
Location: Montreal

Top

Postby Tomas » Mon Sep 21, 2009 12:39 am

The xml file is not "compiled" when you save.

When you save, it just saves the xml file in your project directory. Then you have to compile the whole project again into a .apk file, which you can run on the emulator. Simply editing the main.xml in your project and saving isn't going to change the main.xml in the apk file.
Tomas
Freshman
Freshman
 
Posts: 5
Joined: Sun Sep 20, 2009 1:00 pm

Postby bgoody » Mon Sep 21, 2009 1:11 am

Tomas wrote:The xml file is not "compiled" when you save.

When you save, it just saves the xml file in your project directory. Then you have to compile the whole project again into a .apk file, which you can run on the emulator. Simply editing the main.xml in your project and saving isn't going to change the main.xml in the apk file.


Hmm. But when you select Run, Eclipse is supposed to do that and reload the app into the emulator, which it does but my changes to the main.xml file are not put into effect. It does put the changes into effect if I edit the src/java file. Brian
bgoody
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Sep 20, 2009 2:39 pm
Location: Montreal

Postby yaj786 » Tue Sep 22, 2009 12:03 am

Two things:

1) Where are you putting the android:textColor attribute?

2) Did you use setContentView(R.layout.main) ?
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Postby bgoody » Tue Sep 22, 2009 12:23 am

yaj786 wrote:Two things:

1) Where are you putting the android:textColor attribute?

2) Did you use setContentView(R.layout.main) ?


The android:textColor attribute is inthe main.xml file.
The setContentView(R.layout.main) is in the main .java file under the src directory.

Brian
bgoody
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Sep 20, 2009 2:39 pm
Location: Montreal

Postby yaj786 » Tue Sep 22, 2009 12:26 am

right, but where in the xml file?
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Top

Postby bgoody » Tue Sep 22, 2009 1:07 am

yaj786 wrote:right, but where in the xml file?


Here's a snippit:

<Button android:id="@+id/btnNine" android:padding="0px"
android:text="9" android:gravity="center" android:typeface="serif"
android:textStyle="bold" android:textSize="24sp"
android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_weight="1" android:textColor="#2E4A4AFF"
android:background="@drawable/btn_default_normal" />

Here is the same button in .java file
btnNine.setTextColor(Color.RED);
This is the color that shows up on the phone.


Is it possible that the .java file overrides the main.xml?
I believe the color format is correct but it is not recognised in the main.xml and if I put it in the .java file it throws an error "Color cannot be resolved."

Brian
bgoody
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Sep 20, 2009 2:39 pm
Location: Montreal

Postby yaj786 » Tue Sep 22, 2009 1:28 am

the xml file IS overriden by the java file.

Also, try taking out the alpha part of that text color, (android:textColor="#4A4AFF" instead of what you have)
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Postby bgoody » Tue Sep 22, 2009 1:45 am

yaj786 wrote:the xml file IS overriden by the java file.

Also, try taking out the alpha part of that text color, (android:textColor="#4A4AFF" instead of what you have)


Yeah that did it. I didn't know that the .java overwrote the xml. I thought it was the other way around! I just commented out the .java color line and changed the color as you suggested in the xml and now everything is good. Much appreciated.

I am hacking away at some code I scavenged and some things just can't be googled because noone but me has made that mistake before. Brian
bgoody
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Sep 20, 2009 2:39 pm
Location: Montreal

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 3 guests