Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Getting char on the fly  RSS feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making my first android app, a children's game where there is a rain of chars on the screen and the child must click in a correct one to answer a given question.I did a matrix effect following this tutorial:
http://www.devexchanges.info/2016/11/androip-tip-create-digital-rain-effect.html and works fine
My question: How is the better way to get the character?
 
Saloon Keeper
Posts: 5504
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it works fine, in which way would a "better way" improve on it?
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,
the rain of characters works fine, I don't know the better/correct way to get them when the user click on the screen to answer the question!
Never worked with that before, sorry. Just need an orientation. Should I use onTouchEvent to get that char?I appreciate any snippet o code.
 
Tim Moores
Saloon Keeper
Posts: 5504
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Capturing touch events would be a good start. Taking a brief look at the code, it doesn't seem that it stores which character is at which screen position at a given time. That would need to be added if you want to determine which character was clicked on.
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,
I should have been much more specific:
I don't know how to capture the char in the screen.
I do more or less:


best wishes
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved doing: extends AppCompatTextView implements View.OnTouchListener {
but my code doing the business:

releases a lot of java.lang.StringIndexOutOfBoundsException: length=0; index=0 because many times the user will click on empty space(it's a raining of chars).I wonder if there 's a proper way to avoid that.
 
Tim Moores
Saloon Keeper
Posts: 5504
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If getText does not return any text, or text of zero length, the code should not call chartAt on it.
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, I am doing:

But I still get the same error.
 
Marshal
Posts: 24506
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:If getText does not return any text, or text of zero length, the code should not call chartAt on it.

 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
sorry for my stupidity, but WHAT is a zero length text and how I test that?
 
Paul Clapham
Marshal
Posts: 24506
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String class has a length() which tells you the length of a String. If it returns zero then the length of the text is zero.

There's also an isEmpty() method which returns true if the length of the text is zero.
 
Paul Hayabusa
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, I got it! I used the length method. The Problem I discovered the letter/number touched by the user is NEVER selected. I wonder if I have to change the array of chars raining on the screen for one of the images(what could cause a memory leak).Any thoughts?
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!