• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class defined TextView's appearing on top of eachother

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Android app I have a class with twwo TextViews defined(textView and textView2).

When I run the app they appear on top of eachother.

The layout XML doesn't contain any reference to the TextView's so I can't add to textView2.

How do I deal with this? Is there something I should do in the Java class or should I add the TextView tags to my XML?
 
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

paul a carron wrote:In my Android app I have a class with twwo TextViews defined(textView and textView2).

When I run the app they appear on top of eachother.

The layout XML doesn't contain any reference to the TextView's so I can't add to textView2.

How do I deal with this? Is there something I should do in the Java class or should I add the TextView tags to my XML?


Could you publish a snippet of the class that retrieves the id( R.id) ? And also all  your xml file?
 
paul a carron
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I should have posted this at the start.

Class:


XML:


I feel I should be using RelativeLayout for this but have been messing about with it and can't get it to work.
 
paul a carron
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I've got this for my class:



Now I want to add a 3rd TextView below textView2.

When I do the following it doesn't display. Where am I going wrong?


 
paul a carron
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, textView3 shouldn't be commented out in the above example. It still doesn't display when uncommented.
 
Giovanni Montano
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

paul a carron wrote:Sorry, textView3 shouldn't be commented out in the above example. It still doesn't display when uncommented.


I am not surprised the view are collapsed or overlapsing

First of all you want your app to be  decoupled with the UI, this means it is best practice in Android to use xml files, and not programmatically use RelativeLayout if it is not needed by ad hoc  dynamic variables you want to control with the code.

Most important RelativeLayout needs as it is relative that you decide where the Text, Images, Buttons should be positioned in giving your RELATIVE position to the related  element
this means once you position button 1 you say for instance position button 2 on the right of button 1, then you say position botton3 below button 1 and so on
 
paul a carron
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Giovanni.

I got it to work as I'd like but admittedly it could be done in a much better way.

Here's what I came up with but I'll see about editing it to use the XML:
 
Giovanni Montano
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok but please consider that Android does not like the way to declare layout programatically as in Java Swing. Do not use this code in Github or to give to recruiters:)
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic