Couple Novice Questions

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Couple Novice Questions

Postby chunalt787 » Tue May 18, 2010 9:23 am

I hope this is the right place to post this. So I have been working on a basic app to get my feet wet and I had a few questions.

I find myself doing the entire program inside the onCreate function. The bigger the app gets the more my bad practice flags are going off. The problem I am having however is accessing data outside the app. For example I want to set 5 labels visible and invisible but if I do this in a separate function I will have to recreate the TextView objects. I tried to make them data members of the function but since they have to be final to be accessed from button listeners I couldnt assign them right and it gave me problems. I just feel like I could be doing it better.



I understand the string references but it seems like it would slow things down for what I am trying to do. I want to display data such as:

Name: someName
Age: someAge

So for example the Name: and Age: labels could be string resources but it feels like referencing them would be slower than just doing android:text="Name:" in main.xml. Am I wrong and or missing something here and if I am write where do we want to use string resources?

Thanks
chunalt787
Once Poster
Once Poster
 
Posts: 1
Joined: Tue May 18, 2010 9:15 am

Top

Re: Couple Novice Questions

Postby capnKate » Tue Jun 22, 2010 2:47 pm

I am having however is accessing data outside the app. For example I want to set 5 labels visible and invisible but if I do this in a separate function I will have to recreate the TextView objects.


Could you explain a little more what you're doing in your onCreate()? Also, seeing some of you main.xml would be helpful. Are you setting up your text views there?

-Thanks
capnKate
Freshman
Freshman
 
Posts: 8
Joined: Mon Jun 21, 2010 6:55 pm

Re: Couple Novice Questions

Postby vengeance_mj » Tue Jun 22, 2010 5:27 pm

post the snippet of code which you have written so far and then maybe we can help you
vengeance_mj
Senior Developer
Senior Developer
 
Posts: 174
Joined: Thu Oct 29, 2009 2:32 am

Re: Couple Novice Questions

Postby DMacATTACK » Thu Jun 24, 2010 4:59 am

First off I apologize if my syntax is wrong, I am afterall posting this from my phone.

As per you problem with the textviews:
You need to declare the views a private or public variable, then in onCreate you create an instance of the view, and finally you may use it as you wish in a function:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //excuse syntax. I know a few languages and depend on compilers for exact
  2. //syntax and functions
  3.  
  4. //declare the object
  5. Private Textview namelabel;
  6.  
  7. OnCreate(blah...){
  8.  
  9. //heres where u create the object
  10. namelabel = (TextView) findViewById(R.id.TextView7);
  11. }
  12.  
  13. Private void yourFunction(){
  14. //use it as you please
  15. namelabel.visibility ="false"
  16. }
  17.  
  18. //you should also destroy it at the necessary time, but if not the garbage collector
  19. //usually takes care of this
  20.  
  21.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


-Dan-
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests