FORUMS

PSA: You Can Optimize Your Note 4’s Recents Menu & RAM

The Note 4 never had the fastest Recents Menu, and despite its 3GB of RAM, … more

XDA Picks: Best Apps of the Week (July 25 – Aug 1)

Apps are at the front and center of any smartphone experience, and with over a … more

Voices Of XDA: Orbiting The Earth With Android

Editor’s note: This week’s feature has been written by forum … more

CloudPlayer: DIY HiFi Music Streaming Solution

In our Helpful Guide to Music Streaming Services, we mentioned several different services … more

TextView shows wrong text

13 posts
Thanks Meter: 2
 
By Xintax, Junior Member on 3rd January 2014, 02:55 PM
Post Reply Subscribe to Thread Email Thread
Hi,

i'm reading a book about android app development (Learn Android App Development by Wallace Jackson).
But i'm having troubles with my TextViews..
This is what i get when i open the app on the android emulator:



It is supposed to show data like the planet name, mass, gravity,... I tried to locate the mistake in the code, but i never found it..
I want to copy paste the code, but maybe it's easier if i post the entire project

https://www.dropbox.com/sh/235c7k0psaoejxk/I903eizE7A

Could anyone help me find the bug? :/
 
 
3rd January 2014, 03:00 PM |#2  
coolbud012's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 25
 
More
I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...

Thanks
3rd January 2014, 03:10 PM |#3  
OP Junior Member
Thanks Meter: 2
 
More
Quote:
Originally Posted by coolbud012

I think pasting the activity would be preferred becoz it takes much more time while downloading your code, importing, etc...Also for ppl like me sitting in office without access to particular tools can check the code...

Thanks

Oh yeah sorry, I didn't think of that.

This is the XML:

Code:
<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: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=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_name_label" />
    
    <TextView 
        android:id="@+id/dataView1" 
        android:layout_toRightOf="@+id/textView1" 
        android:layout_marginLeft="75dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_name_label" />
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_mass_label" 
        android:layout_below="@+id/textView1"/>
    
    <TextView
        android:id="@+id/dataView2" 
        android:layout_toRightOf="@+id/textView2" 
        android:layout_alignStart="@+id/dataView1" 
        android:layout_below="@+id/dataView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_mass_label" />
    
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_gravity_label" 
        android:layout_below="@+id/textView2"/>
        
    <TextView 
        android:id="@+id/dataView3" 
        android:layout_toRightOf="@+id/textView3" 
        android:layout_alignStart="@+id/dataView2" 
        android:layout_below="@+id/dataView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_gravity_label" />
    
    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_colonies_label" 
        android:layout_below="@+id/textView3"/>
    
    <TextView android:id="@+id/dataView4" 
        android:layout_toRightOf="@+id/textView4" 
        android:layout_alignStart="@+id/dataView3"
        android:layout_below="@+id/dataView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_colonies_label" />
    
    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_population_label" 
        android:layout_below="@+id/textView4"/>
    
    <TextView 
        android:id="@+id/dataView5" 
        android:layout_toRightOf="@+id/textView5" 
        android:layout_alignStart="@+id/dataView4" 
        android:layout_below="@+id/dataView4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_population_label" />
    
    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_military_label" 
        android:layout_below="@+id/textView5"/>
        

    <TextView 
        android:id="@+id/dataView6" 
        android:layout_toRightOf="@+id/textView6" 
        android:layout_alignStart="@+id/dataView5" 
        android:layout_below="@+id/dataView5" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_military_label" />
    
    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_bases_label" 
        android:layout_below="@+id/textView6"/>
    
    <TextView 
        android:id="@+id/dataView7" 
        android:layout_toRightOf="@+id/textView7" 
        android:layout_alignStart="@+id/dataView6" 
        android:layout_below="@+id/dataView6" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_bases_label" />
    
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label" 
        android:layout_below="@+id/textView7"/>   
        
    <TextView
        android:id="@+id/dataView8"
        android:layout_toRightOf="@+id/textView8"
        android:layout_alignStart="@+id/dataView7"
        android:layout_below="@+id/dataView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label"/>

</RelativeLayout>
And this is the java:

Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	WorldGen earth = new WorldGen("Earth", 5973, 9.78);		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		setStartUpWorldValues();

	}
	protected void setStartUpWorldValues() {
		earth.setPlanetColonies(1);
		earth.setPlanetMilitary(1);
		earth.setColonyImmigration(1000);
		earth.setBaseProtection(100);
		earth.turnForceFieldOn();
		
	}
@SuppressWarnings("unused")
	private void setStartUpScreenText() {
			
			TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
			planetNameValue.setText(earth.planetName);
			
			TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
			planetMassValue.setText(String.valueOf(earth.planetMass));
			
			TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
			planetGravityValue.setText(String.valueOf(earth.planetGravity));
			
			TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
			planetColoniesValue.setText(String.valueOf(earth.planetColonies));
			
			TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
			planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
			
			TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
			planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
			
			TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
			planetBasesValue.setText(String.valueOf(earth.planetBases));
			
			TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
			planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
		}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
3rd January 2014, 03:37 PM |#4  
coolbud012's Avatar
Senior Member
Flag Bangalore
Thanks Meter: 25
 
More
Quote:
Originally Posted by Xintax

Oh yeah sorry, I didn't think of that.

This is the XML:

Code:
<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: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=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_name_label" />
    
    <TextView 
        android:id="@+id/dataView1" 
        android:layout_toRightOf="@+id/textView1" 
        android:layout_marginLeft="75dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_name_label" />
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_mass_label" 
        android:layout_below="@+id/textView1"/>
    
    <TextView
        android:id="@+id/dataView2" 
        android:layout_toRightOf="@+id/textView2" 
        android:layout_alignStart="@+id/dataView1" 
        android:layout_below="@+id/dataView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_mass_label" />
    
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_gravity_label" 
        android:layout_below="@+id/textView2"/>
        
    <TextView 
        android:id="@+id/dataView3" 
        android:layout_toRightOf="@+id/textView3" 
        android:layout_alignStart="@+id/dataView2" 
        android:layout_below="@+id/dataView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_gravity_label" />
    
    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_colonies_label" 
        android:layout_below="@+id/textView3"/>
    
    <TextView android:id="@+id/dataView4" 
        android:layout_toRightOf="@+id/textView4" 
        android:layout_alignStart="@+id/dataView3"
        android:layout_below="@+id/dataView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_colonies_label" />
    
    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_population_label" 
        android:layout_below="@+id/textView4"/>
    
    <TextView 
        android:id="@+id/dataView5" 
        android:layout_toRightOf="@+id/textView5" 
        android:layout_alignStart="@+id/dataView4" 
        android:layout_below="@+id/dataView4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_population_label" />
    
    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_military_label" 
        android:layout_below="@+id/textView5"/>
        

    <TextView 
        android:id="@+id/dataView6" 
        android:layout_toRightOf="@+id/textView6" 
        android:layout_alignStart="@+id/dataView5" 
        android:layout_below="@+id/dataView5" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_military_label" />
    
    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_bases_label" 
        android:layout_below="@+id/textView6"/>
    
    <TextView 
        android:id="@+id/dataView7" 
        android:layout_toRightOf="@+id/textView7" 
        android:layout_alignStart="@+id/dataView6" 
        android:layout_below="@+id/dataView6" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/planet_bases_label" />
    
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label" 
        android:layout_below="@+id/textView7"/>   
        
    <TextView
        android:id="@+id/dataView8"
        android:layout_toRightOf="@+id/textView8"
        android:layout_alignStart="@+id/dataView7"
        android:layout_below="@+id/dataView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label"/>

</RelativeLayout>
And this is the java:

Code:
package chapter.two.hello.world;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	WorldGen earth = new WorldGen("Earth", 5973, 9.78);		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		setStartUpWorldValues();

	}
	protected void setStartUpWorldValues() {
		earth.setPlanetColonies(1);
		earth.setPlanetMilitary(1);
		earth.setColonyImmigration(1000);
		earth.setBaseProtection(100);
		earth.turnForceFieldOn();
		
	}
@SuppressWarnings("unused")
	private void setStartUpScreenText() {
			
			TextView planetNameValue = (TextView)findViewById(R.id.dataView1);
			planetNameValue.setText(earth.planetName);
			
			TextView planetMassValue = (TextView)findViewById(R.id.dataView2);
			planetMassValue.setText(String.valueOf(earth.planetMass));
			
			TextView planetGravityValue = (TextView)findViewById(R.id.dataView3);
			planetGravityValue.setText(String.valueOf(earth.planetGravity));
			
			TextView planetColoniesValue = (TextView)findViewById(R.id.dataView4);
			planetColoniesValue.setText(String.valueOf(earth.planetColonies));
			
			TextView planetPopulationValue = (TextView)findViewById(R.id.dataView5);
			planetPopulationValue.setText(String.valueOf(earth.planetPopulation));
			
			TextView planetMilitaryValue = (TextView)findViewById(R.id.dataView6);
			planetMilitaryValue.setText(String.valueOf(earth.planetMilitary));
			
			TextView planetBasesValue = (TextView)findViewById(R.id.dataView7);
			planetBasesValue.setText(String.valueOf(earth.planetBases));
			
			TextView planetForcefieldValue = (TextView)findViewById(R.id.dataView8);
			planetForcefieldValue.setText(String.valueOf(earth.planetProtection));
		}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}

Have gone through this but didnt get what exactly you are trying to achieve...Also you have posted the main Activity in which you have created a member of "WorldGen" , whats in this class?

Actually to be frank I didnt get what exactly you are trying to do here...

I would be good if you make an image in "Paint" , rough image, and show what you are exactly trying to achieve?

Thanks

---------- Post added at 09:07 PM ---------- Previous post was at 09:06 PM ----------

If possible upload the project on Github.com
3rd January 2014, 04:02 PM |#5  
OP Junior Member
Thanks Meter: 2
 
More
Well i'm trying to get the text on the left to change into the planet name (earth) planet gravity (9.8),...



I think i can't make it more clear with a paint image with my painting skills

I'm setting up github as we speak, i'll upload it in a sec.

EDIT: Here it is: https://github.com/Xintax/HlloWrld

Thanks!
Last edited by Xintax; 3rd January 2014 at 04:19 PM.
3rd January 2014, 11:13 PM |#6  
Member
Thanks Meter: 21
 
More
Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?

Regards
The Following User Says Thank You to EmptinessFiller For This Useful Post: [ View ]
3rd January 2014, 11:28 PM |#7  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 343
 
More
Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.
The Following User Says Thank You to SimplicityApks For This Useful Post: [ View ]
4th January 2014, 09:14 AM |#8  
OP Junior Member
Thanks Meter: 2
 
More
Quote:
Originally Posted by EmptinessFiller

Did you tried hard-coded values?
For ex.: textview1.setText("Earth");
And so on?

Regards

Quote:
Originally Posted by SimplicityApks

Just interested, how long does it take to start the activity on devices not running a Snapdragon 800? Seriously, your layout files shouldn't be nearly as long. Try to use a ListView instead! This is heavily optimised and perfect for what I think you are trying to do here.

Well i tried to hard-code the values, and that works.. But my idea is that users can change the planet, and can make their own, so i can't hard-code the values because then they can't change :/

I'll try if the listview works, it does take a long time
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes